update_android_version.sh 900 Bytes
Newer Older
Lorenz Meier's avatar
Lorenz Meier committed
1
#!/usr/bin/env bash
2 3 4

VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'`

5 6 7 8 9 10
# Android versionCode from git tag vX.Y.Z-123-gSHA
IFS=. read major minor patch dev sha <<<"${VERSIONNAME//-/.}"
VERSIONCODE=$(($major*100000))
VERSIONCODE=$(($(($minor*10000)) + $VERSIONCODE))
VERSIONCODE=$(($(($patch*1000)) + $VERSIONCODE))
VERSIONCODE=$(($(($dev)) + $VERSIONCODE))
11

12
MANIFEST_FILE=android/AndroidManifest.xml
13 14
if [ -n "$VERSIONCODE" ]; then
	sed -i -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"$VERSIONCODE\"/" $MANIFEST_FILE
Lorenz Meier's avatar
Lorenz Meier committed
15
	echo "Android version: ${VERSIONCODE}"
16 17
else
	echo "Error versionCode empty"
18
	exit 0 # don't cause the build to fail
19 20 21 22
fi

if [ -n "$VERSIONNAME" ]; then
	sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE
Lorenz Meier's avatar
Lorenz Meier committed
23
	echo "Android name: ${VERSIONNAME}"
24 25
else
	echo "Error versionName empty"
26
	exit 0 # don't cause the build to fail
27
fi
28