Customize the APK file name for android product flavors

Customize the APK file name for android product flavors

Hello folks, I faced this issue a couple of times.

when we work as a small team in the organization and you don’t have a CI/CD environment.

and there is a situation where we have to share our release or debug APK to the QA team or anyone in the organization.

we have to generate the APK and rename the APK’s name manually by clicking on rename to the APK file.

For example, If you have build version name 1.0.2 which you need to give only to QA then you will rename the APK as app_debug_qa_1.0.2.apk.

but when I came to know that we can rename our APK I got a little smile on my face.

So for renaming your APK file while generating you can add below code to your app-level Gradle file.

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), ''

    flavorDimensions "version"
    productFlavors {
        Free {
            dimension "version"
            applicationId ""
        Paid {
            dimension "version"
            applicationId ""

    // Customize your APK name here
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def appId = variant.applicationId// OR
            def versionName = variant.versionName
            def versionCode = variant.versionCode // e.g 1.0
            def flavorName = variant.flavorName // e. g. Free
            def buildType = // e. g. debug
            def variantName = // e. g. FreeDebug

            //customize your app name by using variables
            outputFileName = "${buildType}.apk"

So in the above code, you will find all your configuration variables, so you can customize your APK as per your requirement.

Here is the Screenshot of Apk which I generated for Debug APK.

Output files

I hope this small setup can help you to reduce your work.

Thanks and Happy New Year.


Posted by Happy Singh

Android Developer

Leave a Reply

Your email address will not be published. Required fields are marked *