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)
gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.
A multi-project build in Gradle consists of one root project, and one or more subprojects. A basic multi-project build contains a root project and a single subproject. This is a structure of a multi-project build that contains a single subproject called app : Example 1. Basic multi-project build.
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" } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With