Browse Source

Fix versionCode scheme

QGC4.4
DonLakeFlyer 4 years ago committed by Don Gagne
parent
commit
35bd6f48d9
  1. 55
      tools/update_android_version.sh

55
tools/update_android_version.sh

@ -1,45 +1,74 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# git tag is in the form vX.Y.Z for builds from tagged commit
# git tag is in the form vX.Y.Z-1234-gSHA for builds from non-tagged commit
# Strip the 'v' from the beginning of the tag
VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'` VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'`
echo "tag $VERSIONNAME"
# Android versionCode from git tag vX.Y.Z-123-gSHA # Change all occurences of '-' in tag to '.' and separate into parts
IFS=. read major minor patch dev sha <<<"${VERSIONNAME//-/.}" IFS=. read major minor patch dev sha <<<"${VERSIONNAME//-/.}"
VERSIONCODE=$(($major*100000)) echo "major:$major minor:$minor patch:$patch dev:$dev sha:$sha"
VERSIONCODE=$(($(($minor*10000)) + $VERSIONCODE))
# Max Android version code is 2100000000. Version codes must increase with each release and the
# version codes for multiple apks for the same release must be unique and not collide as well.
# All of this makes it next to impossible to create a rational system of building a version code
# from a semantic version without imposing some strict restrictions.
if [ $major -gt 9 ]; then
echo "Error: Major version larger than 1 digit: $major"
exit 1
fi
if [ $minor -gt 9 ]; then
echo "Error: Minor version larger than 1 digit: $minor"
exit 1
fi
if [ $patch -gt 99 ]; then
echo "Error: Patch version larger than 2 digits: $patch"
exit 1
fi
if [ $dev -gt 999 ]; then
echo "Error: Dev version larger than 3 digits: $dev"
exit 1
fi
# Version code format: BBMIPPDDD (B=Bitness, I=Minor)
VERSIONCODE=$(($major*1000000))
VERSIONCODE=$(($(($minor*100000)) + $VERSIONCODE))
VERSIONCODE=$(($(($patch*1000)) + $VERSIONCODE)) VERSIONCODE=$(($(($patch*1000)) + $VERSIONCODE))
VERSIONCODE=$(($(($dev)) + $VERSIONCODE)) VERSIONCODE=$(($(($dev)) + $VERSIONCODE))
# The 32 bit and 64 bit APKs each need there own version code. # The 32 bit and 64 bit APKs each need there own version code unique version code
if [ "$1" = "32" ]; then if [ "$1" = "32" ]; then
VERSIONCODE=330$VERSIONCODE VERSIONCODE=34$VERSIONCODE
else else
VERSIONCODE=650$VERSIONCODE VERSIONCODE=66$VERSIONCODE
fi fi
MANIFEST_FILE=android/AndroidManifest.xml MANIFEST_FILE=android/AndroidManifest.xml
# manifest package # manifest package
if [ "$2" = "master" ]; then if [ "$2" = "master" ]; then
echo "Adjusting package name for daily build"
QGC_PKG_NAME="org.mavlink.qgroundcontrolbeta" QGC_PKG_NAME="org.mavlink.qgroundcontrolbeta"
sed -i -e 's/package *= *"[^"]*"/package="'$QGC_PKG_NAME'"/' $MANIFEST_FILE sed -i -e 's/package *= *"[^"]*"/package="'$QGC_PKG_NAME'"/' $MANIFEST_FILE
echo "Android package name: $QGC_PKG_NAME"
fi fi
# android:versionCode # android:versionCode
if [ -n "$VERSIONCODE" ]; then if [ -n "$VERSIONCODE" ]; then
echo "Android versionCode: ${VERSIONCODE}"
sed -i -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"$VERSIONCODE\"/" $MANIFEST_FILE sed -i -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"$VERSIONCODE\"/" $MANIFEST_FILE
echo "Android version: ${VERSIONCODE}"
else else
echo "Error versionCode empty" echo "Error: versionCode empty"
exit 0 # don't cause the build to fail exit 1
fi fi
# android:versionName # android:versionName
if [ -n "$VERSIONNAME" ]; then if [ -n "$VERSIONNAME" ]; then
echo "Android versionName: ${VERSIONNAME}"
sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE
echo "Android name: ${VERSIONNAME}"
else else
echo "Error versionName empty" echo "Error: versionName empty"
exit 0 # don't cause the build to fail exit 1
fi fi

Loading…
Cancel
Save