update_android_version.sh 1.14 KB
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

# manifest package
15
if [ "$2" = "master" ]; then
16
	QGC_PKG_NAME="org.mavlink.qgroundcontroldaily"
17 18 19 20 21
	sed -i -e 's/package *= *"[^"]*"/package="'$QGC_PKG_NAME'"/' $MANIFEST_FILE
	echo "Android package name: $QGC_PKG_NAME"
fi

# android:versionCode
22 23
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
24
	echo "Android version: ${VERSIONCODE}"
25 26
else
	echo "Error versionCode empty"
27
	exit 0 # don't cause the build to fail
28 29
fi

30
# android:versionName
31 32
if [ -n "$VERSIONNAME" ]; then
	sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE
Lorenz Meier's avatar
Lorenz Meier committed
33
	echo "Android name: ${VERSIONNAME}"
34 35
else
	echo "Error versionName empty"
36
	exit 0 # don't cause the build to fail
37
fi
38