How to Change the Default Generated apk Name in Android Studio?

08 Oct, 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. 
Method 1: Updating your build.gradle file to change the APK file nameMethod 2: Updating your build.gradle file to change the APK file nameMethod 3: Updating apk name for debug apkMethod 4: Updating apk name for release apkMethod 5: Renaming your APK name after generating your APK file
Method 1: Updating your build.gradle file to change the APK file name
Method 2: Updating your build.gradle file to change the APK file name
Method 3: Updating apk name for debug apk
Method 4: Updating apk name for release apk
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. 
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 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->                        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. 
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                }        }}
  
 
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                }        }}
  
 
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                }        }}
  
 
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. 
 
kashishsoda
Picked
Android
Android
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Android SDK and it's Components
Flutter - Custom Bottom Navigation Bar
Retrofit with Kotlin Coroutine in Android
How to Post Data to API using Retrofit in Android?
Flutter - Stack Widget
Introduction to Android Development
Data Binding in Android with Example
Animation in Android with Example
Fragment Lifecycle in Android
Flutter - BoxShadow Widget