update_android_version.sh 1.46 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

Don Gagne's avatar
Don Gagne committed
12 13 14 15 16
# The android versionCode is for the entire package. It is the same for the 32 and 64 bit APKs.
# At one point it was thought the versionCode was specific to APK. Hence the 32/64 bitness was
# included as a prefix. That was incorrect. But now we are stuck with version codes starting with
# a prefix of 64.
VERSIONCODE=64$VERSIONCODE
17

18
MANIFEST_FILE=android/AndroidManifest.xml
19 20

# manifest package
21
if [ "$2" = "master" ]; then
22 23 24 25 26 27
	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
28 29
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
30
	echo "Android version: ${VERSIONCODE}"
31 32
else
	echo "Error versionCode empty"
33
	exit 0 # don't cause the build to fail
34 35
fi

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