This is an example of a simple android application which uses different ways to specify build's versionCode
.
In particular, the version code is the incremented latest build number fetched from Google Play Developer API throught google-play
Codemagic CLI Tool.
The latest Google Play build number is obtained in codemagic.yaml
LATEST_GOOGLE_PLAY_BUILD_NUMBER=$(google-play get-latest-build-number --package-name 'io.codemagic.androidhelloworldapp')
Increment it and save to a variable (arbitrary name) if it's not empty.
LATEST_GOOGLE_PLAY_BUILD_NUMBER=$(google-play get-latest-build-number --package-name 'io.codemagic.androidhelloworldapp')
if [ -z LATEST_BUILD_NUMBER ]; then
# fallback in case no build number was found from google play. Alternatively, you can `exit 1` to fail the build
UPDATED_BUILD_NUMBER=$BUILD_NUMBER
else
UPDATED_BUILD_NUMBER=$(($LATEST_GOOGLE_PLAY_BUILD_NUMBER + 1))
fi
Provide the created variable as gradlew argument properties for version code and version name:
./gradlew bundleRelease -PversionCode=$UPDATED_BUILD_NUMBER -PversionName=1.0.$UPDATED_BUILD_NUMBER
In build.gradle
, the version code and name are read inside a function from the passed arguments
def getMyVersionCode = { ->
return project.hasProperty('versionCode') ? versionCode.toInteger() : -1
}
def getMyVersionName = { ->
return project.hasProperty('versionName') ? versionName : "1.0"
}
and used inside the android config
android {
...
defaultConfig {
...
versionCode getMyVersionCode()
versionName getMyVersionName()
-
autoversioning_through_file
branchRead
versionCode
inbuild.gradle
from a createdapp/version.properties
file -
autoversioning_through_executable
branchCall the
google-play
tool directly from thebuild.gradle
to get the build version code -
autoversioning_through_environment_variable
branchRead a created environment variable with build number in
build.gradle