This page describes simple way how to assign versions in build.gradle.kts and Info.plist.
setup_application_version.sh
#!/bin/bash
set -e
# Manually edited by a developer
baseVersion="1.0"
# The application build number is count of commits in release branch (suppose we use one branch to make a release).
buildNumber=$(git rev-list --count "$branch")
# Short hash of a build commit
buildCommit=$(git rev-parse --short "$branch")
versionName="$baseVersion($buildCommit)"
versionNumber=$buildNumber
echo "versionName:$versionName"
echo "versionNumber:$versionNumber"
androidConfig="androidApp/build.gradle.kts"
sed -i "" "s+versionName = \".*\"+versionName = \"$versionName\"+g;
s+versionCode = *[0-9]*+versionCode = $versionNumber+g" $androidConfig
iosConfig="iosApp/iosApp/Info.plist"
sed -i "" "/<key>CFBundleShortVersionString<\/key>/{n;s/<string>.*<\/string>/<string>$versionName<\/string>/;};
/<key>CFBundleVersion<\/key>/{n;s/<string>.*<\/string>/<string>$versionNumber<\/string>/;}" $iosConfig
Examples
build.gradle.kts before
android {
defaultConfig {
versionCode = 1
versionName = "1.0"
}
}
build.gradle.kts after
android {
defaultConfig {
versionCode = 165
versionName = "1.0(125490f)"
}
}
Info.plist before
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Info.plist after
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0(125490f)</string>
<key>CFBundleVersion</key>
<string>165</string>
</dict>
</plist>
Result
By an application version we can definitely determine a build code.
Run this script before build on CI server.