update_android_version.sh 1.22 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 13 14
# Command line specifies either 32 or 64 bit version
VERSIONCODE=$1$VERSIONCODE

15
MANIFEST_FILE=android/AndroidManifest.xml
16 17

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

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

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