I’m developing android app in android studio. My goal is to rename the apk automatically into the next format:
versionName (but replacing ‘.’ with ‘_’) + ‘_’ + md5Hash + .apk. My code for calculating md5hash works, I’m having a problem running the gradle task at the end of everything.
task calculateAndRenameFile(type: DefaultTask) {
outputs.upToDateWhen { false }
dependsOn("assembleDebug")
project.android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFileExists = output.outputFile.exists()
String versionName = variant.versionName.replace('.', '_')
if (outputFileExists) {
String md5Hash = getMd5Hash(output.outputFile)
output.outputFileName = "${versionName}_${md5Hash}.apk"
} else {
println("Skipping variant due to missing outputFile: ${output.outputFile}")
}
}
}
}
afterEvaluate {
calculateAndRenameFile.dependsOn{"assembleDebug"}
}
This is my current code. From build output i see the task does not run at the end at all (was testing with debug build type).
Few stuff i tried without success:
– contents of the task surrounded with doLast() -> causes problems with
project.android.applicationVariants.all
project/android part not being recognized.
I’ve also tried to surround everything into afterEvaluate but output.outputFileName operation is not permited that way.
I’ve also tried few solutions with finilizedBy, but without success.