Android developers using ReactNative, Flutter, Java or Kotlin use Microsoft AppCenter, a free, neat and extremely popular DevOps tool, to automate app build creation and distribution. A popular challenge is the ability to set your App's Version Name and Build Number/Code without making constant code changes, so that you can easily create newer apps with the click of the Build button in AppCenter.
What is the Version Code and Name?
The Version Name is the value that you see in the Play Store as "Current Version" shown below. The version code (or build number) is not visible to the end-user, but just like the version name you cannot upload an app that has a version code less than or equal to the existing one.
Build Settings changes:
If you haven't started using AppCenter, you just need to create a new Android app, select the App language and then connect your Git Repository, then against a specific branch you can select specific build settings so it automatically creates a new build with every Pull Request merged, for your QA to test.
You can manually change the values of the versionCode
and versionName
in your build.gradle
, but that can't be independently done by someone non-technical, and requires another manual code change & pull request by a developer, approval by reviewer of code like this:
versionCode 201
versionName "1.2.1"
Let's automate this!
Overview
Important
Visual Studio App Center is scheduled for retirement on March 31, 2025. While you can continue to use Visual Studio App Center until it is fully retired, there are several recommended alternatives that you may consider migrating to.
Contents
Planning
Over the past few years our team’s focus has been to deliver a first class DevOps experience for mobile and desktop developers. A substantial part of this journey involved building the next generation of HockeyApp services for our customers. Earlier this year, we completed the HockeyApp shut down. We are now looking at what's next for the App Center service.
Just like any software engineering team, as we focused on building and scaling App Center, we accumulated technical debt that can no longer be sustained. Therefore, as we look to what is next, the App…
AppCenter allows you to add pre-build scripts that can provide a lot more flexibility, but this feature is very easy to automate, and doesn't even need a shell script! To understand the changes, it's important to note that Android expects an integer value for Version Code and a string value for Version Name! When you put any value into the AppCenter environment variable dictionary, you can retrieve the values using the System.getenv()
function, so we simply replace our build.gradle
code from above, with 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"
We added the ternary null checker so that the code works if you try to manually deploy from your local machine as well. That's it, just build and give it a test!
Please subscribe so I know people out there want me to write more technical articles in my free time, and feel free to let me know on Twitter if you have any questions. You can support me by following my small business on LinkedIn, to be informed of innovations & products like our free 5-star NumberBomb game on Android & iOS!
Top comments (0)