Gradle: How to run custom task after an Android Library is built?

It seems that finalizedBy might be helpful.

assembleRelease.finalizedBy(copyAARToCommonLibs)

Mind the fact that in the following way you won't define a dependency:

assembleRelease.doLast {
   copyAARToCommonLibs
}

actually.. it does exactly nothing. You need to execute the task:

assembleRelease.doLast {
   copyAARToCommonLibs.execute()
}

but running task in the following way is discouraged and very bad practice.

You can also try:

assembleRelease.doLast {
   copy {
      from('../build/outputs/aar') {
        include '*-release.aar'
      }
      into '../AscendonSDKSamples/libs'
   }
}

I went with finalizedBy() but had to include it within an afterEvaluate...

afterEvaluate {
    if (gradle.startParameter.taskNames.contains(":app:assembleFatReleaseInternal")) {
        play.enabled = true
        play.commit = true
        play.track = "internal"
        play.releaseStatus = "completed"
        play.releaseName = versionName

        generateFatReleaseInternalBuildConfig.dependsOn set_build_date
        assembleFatReleaseInternal.finalizedBy(uploadCrashlyticsSymbolFileFatReleaseInternal)
        uploadCrashlyticsSymbolFileFatReleaseInternal.finalizedBy(publishFatReleaseInternal)
    }
}

This worked well for automating the upload of native symbols to Fabric / Crashlytics and other things such as automated play store publishing.