I'm using Gradle to compile my Android project:
buildTypes {
release {
signingConfig signingConfigs.release
applicationVariants.all { variant ->
def file = variant.outputFile
def fileName = file.name
fileName = fileName.replace(".apk", "-renamed".apk")
variant.outputFile = new File(file.parent, fileName)
}
}
}
Not all output files are renamed, it always skips 1 file. Why?
myapp-debug-unaligned-renamed.apk <-renamed, OK!
myapp-release.apk <-NOT renamed, WRONG!
myapp-release-unaligned-renamed.apk <-renamed, OK!
I simplified it by removing one of your lines but essentially you need to change it like so:
There should be 3 output APK files when using your build.gradle configuration: debug unsigned unaligned, release signed aligned and release signed unaligned. There are two variables for
applicationVariant
to deal with output files: outputFile and packageApplication.outputFile, the former is used for zipalign and the later is used in general case.So the proper way to rename all the files will be like this:
I solved using this code:
The block
applicationVariants.all {...}
is now outside therelease {...}
block.I think
variant.zipAlign.outputFile
makes the difference.