update_android_version.sh 1.29 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 15 16 17
# The 32 bit and 64 bit APKs each need there own version code.
if [ "$1" = "32" ]; then
    VERSIONCODE=330$VERSIONCODE
else
    VERSIONCODE=650$VERSIONCODE
fi
Don Gagne's avatar
Don Gagne committed
18

19
MANIFEST_FILE=android/AndroidManifest.xml
20 21

# manifest package
22
if [ "$2" = "master" ]; then
Don Gagne's avatar
Don Gagne committed
23
	QGC_PKG_NAME="org.mavlink.qgroundcontrolbeta"
24 25 26 27 28
	sed -i -e 's/package *= *"[^"]*"/package="'$QGC_PKG_NAME'"/' $MANIFEST_FILE
	echo "Android package name: $QGC_PKG_NAME"
fi

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

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