update_android_version.sh 1.41 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
# The android versionCode is for the entire package. It is the same for the 32 and 64 bit APKs.
Don Gagne's avatar
Don Gagne committed
13
# Due to various screwups in versioning/tagging the version code needs to be prepended with 650 to
Don Gagne's avatar
Don Gagne committed
14
# make it larger than all previous version codes.
Don Gagne's avatar
Don Gagne committed
15
VERSIONCODE=650$VERSIONCODE
Don Gagne's avatar
Don Gagne committed
16

17
MANIFEST_FILE=android/AndroidManifest.xml
18 19

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

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

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