Skip to content
Related Articles

Related Articles

How to Change the Default Generated apk Name in Android Studio?
  • Last Updated : 12 Mar, 2021

While developing any Android app using Android Studio we generate our APK file after creating our whole Android application. We use this .apk file to publish it to our Google Play console or on any other platform. When we are generating our .apk file for release apk. We always see our apk file name starts with the release.apk file. In this article, we will see 5 different methods of how we can change the apk name for our release apk. 

  1. Method 1: Updating your build.gradle file to change the APK file name
  2. Method 2: Updating your build.gradle file to change the APK file name
  3. Method 3: Updating apk name for debug apk
  4. Method 4: Updating apk name for release apk
  5. Method 5: Renaming your APK name after generating your APK file

Prerequisite: For using this method to rename your apk file you should be having an Android Studio project ready with you. In this, we will be updating our apk name and generate a new APK with a different name. 

Method 1: Updating your build.gradle file to change the APK file name

In this method, we will be adding a code in our build.gradle file to change the name of our .apk file. In this process. navigate to the app > Gradle Scripts > build.gradle file and add the below code in buildTypes section below the release block. The code for the build type section is given below. Comments are added in the code to get to know in more detail. 

XML




buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        // add the code from below line. 
        applicationVariants.all{
            // this methid is use to rename your all apk weather
            // it may be signed or unsigned(debug apk)
            variant ->
                variant.outputs.each{
                    // on below line we are setting a 
                    // name to our apk as GFG.apk
                    output->
                        def name = "GFG.apk"
                        // on below line we are setting the 
                        // outputFile Name to our apk file. 
                        output.outputFileName = name
                }
       }
}

After adding this code in your build.gradle file. Now click on Sync Now option to sync your project and then build your APK. You will get to see your APK name build with the name as GFG.apk. 



Method 2: Updating your build.gradle file to change the APK file name

In this method, we will be adding a simple code snippet in our build.gradle file where we will be updating our apk name with version code. In this process. Navigate to the app > Gradle Scripts > build.gradle file and add below code in buildTypes section below the release block. The code for the build type section is given below. Comments are added in the code to get to know in more detail. In the below process the generated apk name will be GFG(1).apk

XML




buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        // add the code from below line
        applicationVariants.all{
            // this method is use to rename your all apk weather 
            // it may be signed or unsigned(debug apk)
            variant ->
                variant.outputs.each{
                    // on below line we are setting 
                    // a name to our apk as GFG.apk
                    output->
                        // on below line we are adding version name to 
                        // our .apk file along with the app name
                        def name = "GFG(${variant.versionName}).apk"
                        // on below line we are setting the 
                        // outputFile Name to our apk file
                        output.outputFileName = name
                }
        }
}

Method 3: Updating apk name for debug apk

In this method, we will be adding a code snippet with which we can update the apk name for our debug apk only. In this process we have to navigate to the app > Gradle Scripts > build.gradle file and add below code in buildTypes section below the release block. The code for the build type section is given below. Comments are added in the code to get to know in more detail. In the below process the generated apk name will be GFG-debug-2021-03-10-13-07-18.apk 

XML




buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        // add the code from below line.
        applicationVariants.all{
            // this method is use to rename your all apk weather
            // it may be signed or unsigned(debug apk)
            variant ->
                variant.outputs.each{
                    // on below line we are setting a name to our apk
                    output->
                        // on below line we are specifying our app name.
                        project.ext { appName = 'GFG' }
                        // on below line we are adding the formatted date to our apk file name.
                        def formattedDate = new Date().format('yyyy-MM-dd-HH-mm-ss')
                        // on below line we are creating a new name for our apk.
                        def newName = output.outputFile.name
                        // on below line we are replacing our previous name with our app name.
                        newName = newName.replace("app-", "$project.ext.appName-")
                        // on below line we are replacing -debug with our formatted date.
                        newName = newName.replace("-debug", "-debug-" + formattedDate)
                        // at last we are setting our apk name to it. 
                        output.outputFileName  = newName
                }
        }
}

Method 4: Updating apk name for release apk

In this method, we will be adding a code snippet with which we can update the apk name for our release apk only. In this process we have to navigate to the app > Gradle Scripts > build.gradle file and add below code in buildTypes section below the release block. The code for the build type section is given below. Comments are added in the code to get to know in more detail. In the below process the generated apk name will be GFG-release-2021-03-10-13-07-18.apk 

XML




buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        // add the code from below line.
        applicationVariants.all{
            // this method is use to rename your release apk only
            variant ->
                variant.outputs.each{
                    // on below line we are setting a name to our apk
                    output->
                        // on below line we are specifying our app name.
                        project.ext { appName = 'GFG' }
                        // on below line we are adding the formatted date to our apk file name.
                        def formattedDate = new Date().format('yyyy-MM-dd-HH-mm-ss')
                        // on below line we are creating a new name for our apk.
                        def newName = output.outputFile.name
                        // on below line we are replacing our previous name with our app name.
                        newName = newName.replace("app-", "$project.ext.appName-")
                        // on below line we are replacing -release with our formatted date.
                        newName = newName.replace("-release", "-release-" + formattedDate)
                        // at last we are setting our apk name to it.
                        output.outputFileName  = newName
                }
        }
}

Method 5: Renaming your APK name after generating your APK file

In this method, we will update our APK name after generating our APK file. In this method, we simply generate our .apk file using Generate Signed APK option in the Top Action bar in the Build option. After generating your .apk file. Navigate to the folder in which your apk is present. In that folder select your APK file. Right-click on it and click on rename option to rename your APK file. 

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :