I have a build.gradle file in my Android application with the following settings:
android { ... defaultConfig { applicationId "some.app.id" versionName '1.2' versionCode 3 ... } ... }
My AndroidManifest.xml does not contain versionCode and does not contain versionName.
Now I want to create this application on Jenkins and pass BUILD_NUMBER as the version for the application, so each assembly has a higher version.
So, in the task, I call:
./gradlew -PversionCode=$BUILD_NUMBER clean build
When I use "versionCode" to rename "app-release.apk", the versionCode value matches the one passed from the command line:
applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace("app-release.apk", "MyApp_" + "_v" + versionName + "." + versionCode + ".apk")) } }
Summary
So, I have a default value of "versionCode" equal to 3, but when creating Jenkins I want to override it from the command line.
Problem
The problem is that in AndroidManifest inside the build.apk app has a versionCode value of 3 instead of the value from BUILD_NUMBER. I checked it with "aap dump badging"
Question
Can this value "versionCode" from android defaultConfig be overridden by a command line parameter?
I know I could use the function as described in: http://robertomurray.co.uk/blog/2013/gradle-android-inject-version-code-from-command-line-parameter/ but I prefer a simpler a way to simply override, but I can't get it to work.
source share