I'm trying to set a specific version number in the gradle auto-generated APK filename.
Now gradle generates myapp-release.apk
but I want it to look something like myapp-release-1.0.apk
.
I have tried renaming options that seems messy. Is there a simple way to do this?
buildTypes {
release {
signingConfig signingConfigs.release
applicationVariants.each { variant ->
def file = variant.outputFile
variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
I have tried the code above with no luck. Any suggestions? (using gradle 1.6)
I only have to change the version name in one place. The code is simple too.
The examples below will create apk files named named MyCompany-MyAppName-1.4.8-debug.apk or MyCompany-MyAppName-1.4.8-release.apk depending on the build variant selected.
Note that this solution works on both APK and App Bundles (.aab files).
See Also: How to change the proguard mapping file name in gradle for Android project
#Solution for Recent Gradle Plugin
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.company.app"
minSdkVersion 13
targetSdkVersion 21
versionCode 14 // increment with every release
versionName '1.4.8' // change with every release
setProperty("archivesBaseName", "MyCompany-MyAppName-$versionName")
}
}
The above solution has been tested with the following Android Gradle Plugin Versions:
I'll update this post as new versions come out.
#Solution Tested Only on versions 1.1.3-1.3.0 The following solution has been tested with the following Android Gradle Plugin Versions:
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.company.app"
minSdkVersion 13
targetSdkVersion 21
versionCode 14 // increment with every release
versionName '1.4.8' // change with every release
archivesBaseName = "MyCompany-MyAppName-$versionName"
}
}