Increment Build & Version Number of Android App using Azure DevOps & App Centre
Asked Answered
A

4

15

I am using Azure DevOps and AppCenter(Distribution) for implementing my CICD. Based on the steps mentioned below I have implemented the both CI & CD tasks.

Thant means,

I will create the build using Azure Devops (VSTS) & Push that in to App Centre.

Steps I Follow

Here my doubt is,

How I can increment my Build and Version numbers while distributing these builds?
enter image description here

Actinometer answered 4/1, 2019 at 10:30 Comment(0)
W
13

The easy way is to install Mobile App Tasks for iOS and Android extension for Azure DevOps. You get a task "Bump Version" (for Andriod and iOS).

The task change app's version name and code at build time.

Inputs:

sourcePath - Path to android manifest

versionCode - code number that must be an integer (put the build number variable, it's incremented automatically)

versionCodeOffset - a specific number to increment the version code

versionName- user visible name

printFile - output the file before and after changing variables

Another option is to install Colin's ALM Corner Build & Release Tools extension and use the Version Assemblies task following this detailed tutorial.

Check also this question & answer.

Wrongheaded answered 4/1, 2019 at 11:30 Comment(0)
H
2

For anyone still looking for an alternative method, try modifying either the version number, version name or both in the module build.gradle file like below:

 android {
    defaultConfig {
        applicationId 'com.sample.testapp'
        minSdk 28
        targetSdk 31
        versionCode 2
        versionName "2.2"
    }
    ...
  }
Hausmann answered 14/12, 2021 at 2:30 Comment(0)
W
0

You can do almost anything with shell scripting, but I figured out to Automate Build numbering & App versioning for Android WITHOUT shell scripting while using Microsoft AppCenter CI/CD pipelines! You can create 2 environment variables VERSION_CODE & VERSION_NAME and then use them in the build.gradle file like this:

versionCode System.getenv("VERSION_CODE") ? System.getenv("VERSION_CODE").toInteger() : 201
versionName System.getenv("VERSION_NAME") ? System.getenv("VERSION_NAME").toString() : "1.2.1"

More details in this article

Whall answered 11/10, 2021 at 4:57 Comment(0)
S
0

Another option (if you don't want to install an extra plugin in Azure) is using the embedded counter function.

So basically you'll need to create the variable in the root of your pipeline, smth. like this:
versionCode: $[counter('Google_Play_version_offset', 100)]
Then it will autoincrement for each build - 100, 101, 102, etc.

In the gradle task you can pass this value with next:

- task: Gradle@2
      inputs:
        ...
        options: '-PversionCode=$(versionCode)'
        ...

Please also make sure to handle this option in the build.gradle file.

Squalor answered 25/9, 2022 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.