Reputation: 1325
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.
Upvotes: 10
Views: 3695
Reputation: 1362
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"))
}
Upvotes: 16