How to increment build numbers for iOS and Android 👀
Increment Build Number in a smart way 🤔
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 the Build phases Tab.
- Tap on the + icon to add your script to increment the build number automatically.
It’s good to have the name of the script, I titled it as increment-build-script. sh.
#Update build number with number of git commits if in release mode
if [ ${CONFIGURATION} == "Release" ]; then
buildNumber=$(git rev-list HEAD | wc -l | tr -d ' ')
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi;
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
}
PS: Pardon, if any bad grammar included
Â