Just like many roads, bring you to Bruges, there are number of methods to update your Android build code.
If I hear you think; “Android build code, what’s that again?”, let’s explain shortly. Every android apk or aab you make, has a version name and a version code. While the version name can be any string you want, and will be used to show in the Play Store, the version code has to be a number. There is also an important requirement for when uploading your app to the Play Store. The number has to be higher than your previous upload!
There’s a few strategies to hold on to regarding this number:
- Increasing number (1, 2, 3)
- Use the semantic version in it (1.0.0 => 100)
- Use a random/increasing number from your Continuous Integration
- Use a timestamp
And I’ve used many ways to increase this number. From simply increasing and committing it to writing Gradle code to parse a gradle.properties or using a fastlane plugin.
Recently I came across the best way to do it. I was so puzzled this isn’t known any better that I had to write about it!
You can just while building (on ci) increase this code with whatever you want, with a gradle property!
./gradlew assembleRelease -Pandroid.injected.version.code=32 -Pandroid.injected.version.name="1.0.0"
I’m really hoping this get used a little more in the future. Cause this really is the best way to dynamically update the number while building on your continuous integration system! I try to get the word out!
Originally published at https://eliaslecomte.be.