Page Banner

How to append version name in Android apk file name using Gradle?

You might want to append your app version name in the name of your app’s apk. Specially, when you release your app frequently. Doing this you can distinguish the apk files easily. You may try the following two ways to include the version name in apk name automatically.

Open build.gradle file inside project’s module and proceed with any one of the following fixes-

Fix 1: Include archivesBaseName = “YourAppName-$versionName in defaultConfig{}.

defaultConfig {
    applicationId "your.package.name"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.0"
    archivesBaseName = "YourAppName-$versionName"
}

Fix 2: Include project.ext.set(“archivesBaseName”, “YourAppName-” + versionName); in defaultConfig{}.

defaultConfig {
    applicationId "your.package.name"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.0”
     project.ext.set("archivesBaseName", "YourAppName-" + versionName);

}
Note: Both the fixes have been tested on Gradle plugin 2.1.0.