Reputation: 21864
Is it possible in any way, or, what is the best scenario to programatically update the version code and the version name in an Android Mobile app?
For a mobile app we use:
our continuous integration flow goes like:
Visual studio (xamarin) ->
Git(Code) ->
Build ->
Test(Xamarin testcloud) ->
Release Google Play (Alpha/Beta/Production)
Currently I have to update the version code/name manually before committing to Git, otherwise, on the other end of the flow, Google will complain the version number of the newly released apk is less or equal than the apk already in the Play Store.
However, since we commit a lot and automatically build-release, we only want to increase the version-code/name only on a successful release (in case google rejects it). This caused this little dilemma: Because then the AndroidManifest, where the versioning resides is already packaged in a signed and zipped APK.
Another thing is: we are working with multiple developers on the project so the manual update thing can cause racing conditions, so the best way is (what we think) to update the version numbers just before release.
Things I thought of:
But still a bit stuck and looking for a common / best practice
Upvotes: 0
Views: 564
Reputation: 1522
Caspar,
I took the approach of modifying the manifest before building/packaging the application, because once you start to build, package, sign, zip align, it's to late in the process.
In your build definition, as a first task, before the build task, add a task that will update the manifest:
Arguments:
-filePath '$(FilePath)' -oldValue '$(OldValue)' -newValue '$(NewValue)'
Script:
param ([string] $filePath, [string] $oldValue, [string] $newValue)
Write-Host "---Replacing value $oldValue with new value $newValue in file $filePath---"
$content = [System.IO.File]::ReadAllText($filePath).Replace("$oldValue", $newValue)
[System.IO.File]::WriteAllText($filePath, $content)
$filePath parameter is the path to your manifest such as:
$(Build.SourcesDirectory)\MyAndroidApp\Properties\AndroidManifest.xml
$oldValue parameter would be the version code property:
android:versionCode="1"
$newValue parameter would be the new version code property:
android:versionCode="$(AndroidVersionCode)"
"$(AndroidVersionCode)" could be a variable in your build definition, allowed at queue time or the build number.
I gave you the simple path but for maintainability and convenience I took advantage of the VSTS Task groups. At the end my script to replace text in file is a task group and I can use it in any build definition.
You end up with something like this:
Upvotes: 1