Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate apk name as package name in Android Studio

Android studio will generate default apk name as app-(release|debug).apk.
How to generate apk file name same as package name of the app like com.example-debug.apk.

like image 466
Bangaram Avatar asked Sep 08 '15 05:09

Bangaram


3 Answers

You can do it without using another tasks, setting the 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" );
like image 102
Gabriele Mariotti Avatar answered Oct 12 '22 01:10

Gabriele Mariotti


Try putting this in your module's build.gradle

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)
    }
}
like image 22
slezadav Avatar answered Oct 12 '22 00:10

slezadav


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

this code may be useful for 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 your code:)

like image 31
John smith Avatar answered Oct 12 '22 01:10

John smith