Android: How to change the specific name of the generated apk file in Android Studio?

The default IDE is genarate apk like app-debug.apk or app-release.apk , but I need to generate a specific apk name for the application.

For example: My application name is iPlanter , so I need to generate iPlanter-debug.apk or iPlanter-release.apk instead of app-debug.apk or app-release.apk respectively.

Thanks,

+6
source share
7 answers

Step 1: Go to the root of the main project in the application , right-click on the application and configure the application with a specific name (iPlanter example) and click ok

Step 2: Go to the project settings file, which is setting.gradle

setting.gradle file contains

 include ':app' 

Now you need to replace the application with a specific name.

For an example app, replace it with iPlanter to include ': application', it looks below

 include ':iPlanter' 

then run the Sync project, and then run the application. Finally, the application generates apk, for example iPlanter-debug.apk or iPlanter-release.apk .

+8
source

You can use this for the name of the application with the current date and version.

 android { def version = "2.4"; def milestone = "1"; def build = "0"; def name = getDate()+"APP NAME WHAT YOU WANT"+"v"+version signingConfigs { config { …. } } compileSdkVersion Integer.parseInt(COMPILE_SDK) buildToolsVersion BUILD_TOOLS_VERSION defaultConfig { applicationId "com.PACKAGENAME" minSdkVersion Integer.parseInt(MIN_SDK_LIBRARY) targetSdkVersion Integer.parseInt(TARGET_SDK) versionCode 11 versionName "2.3" multiDexEnabled true } buildTypes { debug { applicationVariants.all { variant -> variant.outputs.each { output -> def apk = output.outputFile; def newName; newName = apk.name.replace("-" + variant.buildType.name, "") .replace(project.name, name); newName = newName.replace("-", "-" + version + "-" + milestone + "-" + build + "-"); output.outputFile = new File(apk.parentFile, newName); } } } 
+5
source

Try this code:

 defaultConfig{ applicationVariants.all { variant -> changeAPKName(variant, defaultConfig) } } def changeAPKName(variant, defaultConfig) { variant.outputs.each { output -> if (output.zipAlign) { def file = output.outputFile output.packageApplication.outputFile = new File(file.parent, "Your APK NAME") } def file = output.packageApplication.outputFile output.packageApplication.outputFile = new File(file.parent, "Your APK NAME") } } 
+2
source

On my PC, it’s enough to rename (through refactoring) the application to the desired name yourName . After that, include ':app' in the settings.grandle file will be changed to include ':yourName' . However, in my case, I need to close / reopen Android Studio due to a synchronization error. As a result, we get apk something like yourName-debug.apk and yourName-release.apk .

0
source

Just add

  archivesBaseName = "NAME_YOU_WANT" 

in the android file {} of your gradle file.

You will receive "NAME_YOU_WANT-release.apk" as the name of the generated file.

0
source

This will help you. This code will create the application name, for example iPlanter-release.apk or iPlanter-debug.apk

 buildTypes { applicationVariants.all { variant -> variant.outputs.each { output -> project.ext { appName = 'iPlanter' } def newName = output.outputFile.name newName = newName.replace("app-", "$project.ext.appName-") output.outputFile = new File(output.outputFile.parent, newName) } } 

}

0
source

For Android Studio 3, this works for me:

 applicationVariants.all { variant -> variant.outputs.all { output -> outputFileName = new File("AppName-" + variant.versionName + ".apk"); } } 
0
source

All Articles