Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a different naming convention for signed apks generated using the wizard on Android Studio

I have an app with more than a few buildFlavors and three different buildTypes.

I generate the signed apks from Build -> Generate Signed APK.... (Unless there is no other go I'd like to continue using the wizard and not create a script, because i have a constantly increasing set of apps and do not want to modify the script every time.)

The generated apks are named in the following pattern:

app-flavorName-buildType.apk

How can i change the naming pattern to something like this:

app_flavorName_buildType_versionCode.apk

Changes I want to make:

  1. Suffix file name with versionCode
  2. Replace hyphens with underscores

I used to do it in ant using task, but not sure how to do it with gradle.

Trying to figure a solution to create the name straight away in the new pattern rather than trying to rename it once it is generated. Is that possible?

I tried looking under Settings -> Gradle but did not find anything. Any other place i should be looking?

like image 794
AndroidMechanic - Viral Patel Avatar asked Jan 19 '16 07:01

AndroidMechanic - Viral Patel


1 Answers

It is not exactly what you are looking for.

You can use your build.gradle to set this attribute:

android {
    //...

    defaultConfig {
        //...
        project.ext.set("archivesBaseName", "app_"+ defaultConfig.versionCode);
    }
}

Assigning the archivesBaseName you will obtain something like:

app_0.9.6-flavorName-buildType.apk

This attribute requires the gradle-plugin 1.3.1 or higher.

Otherwise you have to use a task to rename the apk after building.

like image 131
Gabriele Mariotti Avatar answered Oct 17 '22 10:10

Gabriele Mariotti