1
votes

How should I increase my version number in an android project, as a step of build pipeline app center deployment? Does the Azure DevOps has a version manager plugin, or should I create a version.properties file and edit, commit, push into the current branch?

Build pipeline:

enter image description here

4

4 Answers

0
votes

Unfortunately is no out of the box support, but you can find here a good tutorial:

  • Install Colin's ALM Corner Build & Release Tools that include Version Assemblies task.

  • In the Android manifest the name and code should look like this:

    android:versionCode="1" android:versionName="1.0.0"

  • Add the “Version Assemblies” task TWICE, once for the version name and once for the version code.

enter image description here

Once added, we will bump the name.

First insert the following (with examples):

  • Source Path: src/MobileApps/MyDriving/MyDriving.Android/Properties
  • File Pattern: AndroidManifest.xml
  • Build Regex Pattern: (?:\d+.\d+.\d+.)(\d+)

Under Advanced:

  • Build Regex Group Index: 0
  • Regex Replace Pattern: versionName=“\d+.\d+.\d+
  • Prefix for Replacements: versionName=”

enter image description here

What this will do is update the version name to the Build number format found under “General”, which mine is set to 1.0.0$(rev:.r)

enter image description here

Now for the next one, which is the version code:

  • Source Path: src/MobileApps/MyDriving/MyDriving.Android/Properties
  • File Pattern: AndroidManifest.xml
  • Build Regex Pattern: (?:\d+.\d+.\d+.)(\d+)

Under Advanced:

  • Build Regex Group Index: 1
  • Regex Replace Pattern: versionCode=“\d+
  • Prefix for Replacements: versionCode\

enter image description here

And just like that you are good to go. This will simply update it with the current version revision :)

0
votes

There is an existing task called Mobile App Tasks for iOS and Android in the marketplace which was developed by James Montemagno

You can find the step-by-step instruction in the github

He has developed this task mainly to address this kind of versioning in both android/IOS Apps.

0
votes

The best solution for me was make a version.properties file to track versioning and then modify it during the pipeline build process (shell script). The others are bad especially for custom versioning.

-1
votes

This can be done more clean with out using the properties file and then replacing that using a shell script.

In the top level build.gradle file, under the build scripts:

buildscript {

    def getVersionCode = { ->
        def code = project.hasProperty('versionCode') ? versionCode.toInteger() : -1
        println "VersionCode is set to $code"
        return code
    }

    
    def getVersionName = { ->
        def name = project.hasProperty('versionName') ? versionName : "1.0"
        println "VersionName is set to $name"
        return name
    } 

    ext{
        versionCode = getVersionCode()
        versionName = getVersionName()
    }
}

In your module specific gradle file :

defaultConfig {
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
}

In your Devops pipeline for the gradle build task, just pass on the options like so:

-PversionName=$(Build.BuildNumber) -PversionCode=$(Build.BuildId)