Use different build numbers for every build — automatically using a gradle script

Another JIRA ticket with a crash report from a client: “The app always crashes when filtering the products”. No more information given. Is it a new crash? How can we reproduce it? Which app version was he using? After calling the client, I found out that the crash happens only on his Samsung tablet with the app version 1.1.2. When testing it on our devices I couldn’t reproduce it. The crash tracking captured the crash but it didn’t made any sense. A NullPointerException inside a comment?

Increase the build number with Jenkins

Increasing the build number for every build on Jenkins works — it’s common practice. The only thing that bugs me is that a larger Jenkins build number doesn’t mean a newer app state. The number increases whether I build version 2.3.6 or 1.0.1.

Good build numbers

In my opinion, a good build number shows the current state of the software version. It’s not a timestamp or a random increasing number, so it shouldn’t change when I build a version twice! A bigger number indicates a more advanced version of the software because we all know; A higher number is always better, everybody understands that.

Static build numbers for git

I thought a lot about this problem and came up with the following solution:

Multiple branches

The number alone doesn’t solve the multi branch problem. To solve this I add a second part to the build number, the commit count on the feature branch since last merging the default branch and a two character identifier (hash) of the branch name (example: 825-ud4). When you see another build with the same build number (825-za2) it’s easy to recognize that both builds are build on top of the same commit (build number 825). Apparently those builds are from different branches because of different branch identifiers.

Local Changes

Sending debug builds to the client is not a common practice. But it happens that a debug app version stays on a device of the client because a bug on that specific device required debugging on it. I also share the same test devices with QA. Identifying debug builds with local changes is very important.


Add it to your project

It’s so easy. I wrote this logic as a gradle scriptscript which you can apply with a single line and access the version name with the ext.gitVersionName variable. The configuration is optional.


Some of you may use Jake Whartons’ lazy strategy to generate a build number. This is a big help, but manually increasing a build version is something I always forget.

Easy, isn’t it?

Please let me know what you think about my git versioner — testing it in your current project will take you only a few seconds. I’m excited to get your feedback!

Google Developer Expert for Flutter and passionate Android developer #kotlin working at @grandcentrix in Cologne

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store