I have an app with different flavors - each flavor has two buildTypes.
After renaming some lines in my manifest i also rename the apk. Everything works fine - I just wonder why I get the same apks twice? Once not renamed and once renamed...
Short example of the same app with different Names:
Here is the code of my build.gradle file:
// *** OVERRIDE data in MANIFEST ***
android.applicationVariants.each { variant ->
variant.processManifest.doLast {
overrideDataInManifest(variant)
}
}
def overrideMapsKey(buildVariant){
def appName = getAppName(buildVariant)
// override line ... this is not necessary to this question
renameAPK(buildVariant, appName)
}
// *** RENAME APK ***
def renameAPK(buildVariant, appName){
def apk = buildVariant.packageApplication.outputFile;
def newName = "";
// get data for apk renaming
def versionName = android.defaultConfig.versionName
def versionNameSuffix = buildVariant.buildType.versionNameSuffix
if(versionNameSuffix.toString().equals("null"))
versionNameSuffix = ""
def buildTypeOfApp= buildVariant.buildType.name
if (buildVariant.zipAlign) {
newName = "etscanner-" + appName + "-" + buildTypeOfApp.toUpperCase() + "-v" + versionName + versionNameSuffix + ".apk"
}else{
newName = "etscanner-" + appName + "-" + buildTypeOfApp.toUpperCase() + "-v" + versionName + versionNameSuffix + "-ALIGNED" + ".apk"
}
buildVariant.packageApplication.outputFile = new File(apk.parentFile, newName);
}
Just want to know whats going on and if the same task is possible without getting two apks.
There will always be two APK files for variant with zipAlign option set to true. At first gradle builds the original APK file, then zipalign it and produces optimised version without deleting the original one.
buildVariant.packageApplication.outputFile is the intermediate product of the building process and in my observation that one is always unaligned APK file.
buildVariant.outputFile is the final output where zipAlign option is applied.
On the other hand you might want to correct the build.gradile file, it actually renames the unaligned version of APK file to "ALIGNED" version and leaves the zipalign APK file untouched. Here's my modified version:
if (buildVariant.zipAlign) {
newName = "etscanner-" + appName + "-" + buildTypeOfApp.toUpperCase() + "-v" + versionName + versionNameSuffix + "-ALIGNED.apk"
buildVariant.outputFile = new File(apk.parentFile, newName);
}
newName = "etscanner-" + appName + "-" + buildTypeOfApp.toUpperCase() + "-v" + versionName + versionNameSuffix + "-UNALIGNED" + ".apk"
buildVariant.packageApplication.outputFile = new File(apk.parentFile, newName);
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