I wish to rename my apk from gradle. I have the following lines inside build
applicationVariants.all { variant ->
def file = variant.outputFile
def filename = file.name.replace("SomeXXX", "SomeYYY")
variant.outputFile = new File(file.parent, filename)
}
This successfully renames the apks but not the unaligned apks. Please someone throw some light on this.
The gradle plugin has moved on since you posted this, however to get this working on with the current plugin (v1.0.0), you can use the following:-
variant.outputs.each { output ->
def alignedOutputFile = output.outputFile
def unalignedOutputFile = output.packageApplication.outputFile
// Customise APK filenames (to include build version)
if (variant.buildType.zipAlignEnabled) {
// normal APK
output.outputFile = new File(alignedOutputFile.parent, alignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
}
// 'unaligned' APK
output.packageApplication.outputFile = new File(unalignedOutputFile.parent, unalignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With