How to Change the Default Generated apk Name in Android Studio?
Last Updated :
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 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.
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 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.
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.
Similar Reads
How to Change the Default Icon of Android App? In order to get the app published in stores like Google Play Store, Amazon App Store, etc, or if you just want to personalize the app, the default icon can be changed. We can change the icon of the Android App by using Android Studio itself and by following the below steps: Step 1: Create Android St
2 min read
How to Generate Signed Apk in Android Studio? Signed Apk generates a key and this key can be used to release versions of the app, so it is important to save this key which will be used when the next version of the app is released. The Android system needs that all installed applications be digitally signed with a certificate whose private key i
3 min read
How to Change the API SDK Level in Android Studio? Generally, API level means the Android Version. This determines which version the developers are targeting their application and what is going to be the minimum level of the android version in their application will run. For setting the Minimum level and Maximum level android studio provides two ter
2 min read
How to Generate Signed AAB File in Android Studio? In this article, you will learn how to create an Android App Bundle (AAB) file for an Android app. An Android App Bundle is a publishing format that includes all your appâs compiled code and resources. Your application should be digitally signed with a key in order to publish it on the Google Play s
2 min read
How to Install an APK on the Emulator in Android Studio? In this article, we will know, how we can install APK in our Android Studio Emulator. There are several methods to do that but most of them are quite unreliable and confusing but in this article, we are going to do that with some very easy methods with some very easy steps. Method 1 Step 1: Opening
2 min read