Generate apk name as package name in Android Studio

Android Studio will create the default apk name as app- (release | debug) .apk.
How to generate apk file name in the same way as application package name like com.example-debug.apk .

+7
android android-studio android-gradle apk package-name
source share
5 answers

You can do this without using other tasks by setting archivesBaseName .

For example:

  defaultConfig { .... project.ext.set("archivesBaseName", "MyName-" + defaultConfig.versionName); } 

Output:

 MyName-1.0.12-release.apk 

In your case:

 project.ext.set("archivesBaseName", "com.example" ); 
+15
source share

Try putting this in your build.gradle module

 applicationVariants.all { variant -> variant.outputs.each { output -> def file = output.outputFile def appId = android.defaultConfig.applicationId def fileName = appId + "-" variant.buildType.name +".apk" output.outputFile = new File(file.parent, fileName) } } 
+4
source share

You can see this link. or Illogical to rename your release|debug.apk with the name you want in the file browser.

this code may be useful to you:

 buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' applicationVariants.all { variant -> variant.outputs.each { output -> def formattedDate = new Date().format('yyyyMMddHHmmss') def newName = output.outputFile.name newName = newName.replace("app-", "$rootProject.ext.appName-") //"MyAppName" -> I set my app variables in the root project newName = newName.replace("-release", "-release" + formattedDate) //noinspection GroovyAssignabilityCheck output.outputFile = new File(output.outputFile.parent, newName) } } } debug { } } 

enjoy the code :)

+1
source share

Create a file called customname.gradle in the top-level directory of the project. Paste this code into it.

 android.applicationVariants.all { variant ->; def appName //Check if an applicationName property is supplied; if not use the name of the parent project. if (project.hasProperty("applicationName")) { appName = applicationName } else { appName = parent.name } variant.outputs.each { output ->; def newApkName //If there no ZipAlign task it means that our artifact will be unaligned and we need to mark it as such. if (output.zipAlign) { newApkName = "${appName}-${output.baseName}-${variant.versionName}.apk" } else { newApkName = "${appName}-${output.baseName}-${variant.versionName}-unaligned.apk" } output.outputFile = new File(output.outputFile.parent, newApkName) }} 

Then in your gradle application module add this code

 apply from: "../customname.gradle" 
0
source share

It might help you. This code will create the application name, for example applicationId-release.apk or applicationId-debug.apk , in which applicationId can be your package name.

 buildTypes { applicationVariants.all { variant -> variant.outputs.each { output -> def newName = output.outputFile.name newName = newName.replace("app-", applicationId) output.outputFile = new File(output.outputFile.parent, newName) } } } 
0
source share

All Articles