How to customize the APK file name for product flavors? How to customize the APK file name for product flavors? android android

How to customize the APK file name for product flavors?


Try to put this in your android closure of build.gradle

buildTypes {    debug {        // debug buildType specific stuff    }    release {        // release buildType specific stuff    }    applicationVariants.all { variant ->        if (variant.buildType.name.equals("release") &&            variant.productFlavors[0].name.equals("green") &&            variant.zipAlign) {                def apk = variant.outputFile;                variant.outputFile = new File(apk.parentFile, "green.apk");        } else if(variant.buildType.name.equals("release") &&            variant.productFlavors[0].name.equals("blue") &&            variant.zipAlign) {                def apk = variant.outputFile;                variant.outputFile = new File(apk.parentFile, "blue.apk");        }    }}

Now the outputs should be like green.apk and blue.apk.


This will help you in 2021.

android {    //........flavorDimensions "version"productFlavors {    Free {        dimension "version"        applicationId "com.exampleFree.app"    }    Paid {        dimension "version"        applicationId "com.examplePaid.app"    }}applicationVariants.all { variant ->    variant.outputs.all { output ->        def appId = variant.applicationId// com.exampleFree.app OR com.examplePaid.app        def versionName = variant.versionName        def versionCode = variant.versionCode // e.g 1.0        def flavorName = variant.flavorName // e. g. Free        def buildType = variant.buildType.name // e. g. debug        def variantName = variant.name // e. g. FreeDebug        //customize your app name by using variables        outputFileName = "${variantName}.apk"    }}}

Apk name FreeDebug.apk

Proofenter image description here

enter image description here


For Android Gradle Plugin 0.13.+ you should use something like this:

android{    buildTypes {        applicationVariants.all { variant ->            variant.outputs.each { output ->                def apk = output.outputFile;                def newName = "mysms-" + variant.baseName.replace("-release", "") + "-" + defaultConfig.versionName + ".apk";                output.outputFile = new File(apk.parentFile, newName);            }        }    }}