Making sure when you use VSTS build numbers to version Android Packages they can be uploaded to the Google Play Store
Background
I have a VSTS build extension that can apply a VSTS generated build number to Android APK packages. This takes a VSTS build number and generates, and applies, the Version Name (a string) and Version Code (an integer) to the APK file manifest.
The default parameters mean that the behaviour of this task is to assume (using a regular expression) the VSTS build number has at least three fields major.minor.patch e.g. 1.2.3, and uses the 1.2 as the Version Name and the 3 as the Version Code.
Now, it is important to note that the Version Code must be a integer between 1 and 2100000000 and for the Google Play Store it must be incrementing between versions.
So maybe these default parameter values for this task are not the best options?
The problem the way we use the task
When we use the Android Manifest Versioning task for our tuServ Android packages we use different parameter values, but we recently found these values still cause a problem.
Our VSTS build generates build numbers with four parts $(Major).$(Minor).$(Year:yy)$(DayOfYear).$(rev:r)
- $(Major) – set as a VSTS variable e.g. 1
- $(Minor) – set as a VSTS variable e.g. 2
- $(Year:yy)$(DayOfYear) – the day for the year e.g. 18101
- $(rev:r) – the build count for the build definition for the day e.g. 1
So we end up with build numbers in the form 1.2.18101.1
The Android version task is set in the build to make
- the Version Number {1}.{2}.{3}.{4} - 1.2.18101.1
- the Version Code {1}{2}{3}{4} – 12181011
The problem is if we do more than 9 builds in a day, which is likely due to our continuous integration process, and release one of the later builds to the Google Play store, then the next day any build with a lower revision than 9 cannot be released to the store as its Version Code is lower than the previously published one e.g.
- day 1 the published build is 1.2.18101.11 so the Version Code is 121810111
- day 2 the published build is 1.2.18102.1 so the Version Code is 12181021
So the second Version Code is 10x smaller, hence the package cannot be published.
The Solution
The answer in the end was straightforward and found by one of our engineers Peter (@sarkimedes). It was to change the final block of the VSTS build number to $(rev:rrr), as detailed in the VSTS documentation. Thus zero padding the revision from .1 to .001. This allows up to 1000 builds per day before the problem of altering the Version Code order of magnitude problem occurs. Obviously, if you think you might do more than 1000 internal builds in a day you could zero pack as many digits as you want.
So using the new build version number
- day 1 the published build is 1.2.18101.011 so the Version Code is 1218101011
- day 2 the published build is 1.2.18102.001 so the Version Code is 1218102001
So a nice fix without any need to alter the Android Manifest Versioning task’s code. However, changing the default Version Code parameter to {1}{2}{3} is probably advisable.