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

3 4 5
# this requires `master` in the git tree
#  travis-ci branch builds are unable to set the version properly

6 7
MANIFEST_FILE=android/AndroidManifest.xml

8 9 10 11 12 13
VERSIONCODE=`git rev-list master --first-parent --count`
VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'`

echo "VersionCode: ${VERSIONCODE}"
echo "VersionName: ${VERSIONNAME}"

14 15
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
16
	echo "Android version: ${VERSIONCODE}"
17 18
else
	echo "Error versionCode empty"
19
	exit 0 # don't cause the build to fail
20 21 22 23
fi

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