Increment Build Number in a smart way 🤔

TRINADH KOYA
Nov 20, 2020

--

Hello, I am more of a programmer than a content writer. In this tutorial, ‘am gonna put some simple and easy tricks I have learned so far. Let’s get this started.

Increment Build Number/Version Code Automatically

This is purely based on the number of git commits. I liked it.

iOS:

Go to your project Target, on the right side you will see Build Phases. Tap on Build phases Tab. Tap on + icon to add your script to increment build number automatically. It’s good to have the name of the script, I titled it as Increment Build.
https://gist.github.com/trinadhkoya/aa30980782ad363587073105a7635064#file-incrementbuild-sh

Android:

The following snippet should be placed in build.gradle(project) level. It will check the commit number of your master branch and change

ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "16.0.0"
getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--count', 'master'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
}
catch (ignored) {
return -1;
}
}}

just call this getVersionCode in your app level build.gradle file to get the dynamic version code.

defaultConfig {
applicationId "com.example.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.getVersionCode()
versionName "4.0"
multiDexEnabled true}

It’s never too late to ask me for some advice or help. And also, feel free to comment your version of it too.

#ThereIsOneMoreThing #ComingSoon

--

--

TRINADH KOYA
TRINADH KOYA

Written by TRINADH KOYA

Python lover by passion, React Native Engineer by Profession. For sure, these are not the only ones I worked on 😉 .

No responses yet