From 51a0ea93476aed899c9225ec286e317252043a2d Mon Sep 17 00:00:00 2001 From: Oliver Bock Date: Thu, 13 Apr 2017 11:30:54 +0000 Subject: [PATCH] Android: use dynamic versioning instead of hard-coded values * Use commit date as version code * Derive version name from release tag and add commit SHA1 * No more manual updates required, just proper release tagging! * Resolves https://github.com/BOINC/boinc/issues/1864 (for Android) --- android/BOINC/app/build.gradle | 42 +++++++++++++++++++ .../BOINC/app/src/main/AndroidManifest.xml | 4 +- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/android/BOINC/app/build.gradle b/android/BOINC/app/build.gradle index 4024c93be7..5f451671db 100644 --- a/android/BOINC/app/build.gradle +++ b/android/BOINC/app/build.gradle @@ -1,5 +1,45 @@ +plugins { + id 'org.ajoberstar.grgit' version '1.7.1' + id 'com.palantir.git-version' version '0.7.1' +} + apply plugin: 'com.android.application' +import org.ajoberstar.grgit.Grgit + +// Use commit date as version code +def buildVersionCode() { + def repo = Grgit.open() + def head = repo.head() + + // Sanity check across git plugins + assert head.getAbbreviatedId(10) == versionDetails().gitHash : "Internal error: SHA1 mismatch!" + + return head.time +} + +// Derive version name from release tag and add commit SHA1 +def buildVersionName() { + def pattern = /client_release\/\d+\.\d+\/(?\d+)\.(?\d+)\.(?\d+)(?[-_].*)/ + def message = 'Invalid release tag encountered:' + + def tag = versionDetails().lastTag + def match = (tag =~ pattern) + + // Sanity checks for tag format + assert match.hasGroup() : "$message $tag" + assert 1 == match.size() : "$message $tag" + assert 5 == match[0].size() : "$message $tag" + + def major = match.group('major') + def minor = match.group('minor') + def revision = match.group('revision') + def suffix = match.group('suffix') + def commit = versionDetails().gitHash + + return "${major}.${minor}.${revision}${suffix} (${commit})" +} + android { compileSdkVersion 23 buildToolsVersion "25.0.0" @@ -8,6 +48,8 @@ android { applicationId "edu.berkeley.boinc" minSdkVersion 16 targetSdkVersion 23 + versionCode buildVersionCode() + versionName buildVersionName() } buildTypes { diff --git a/android/BOINC/app/src/main/AndroidManifest.xml b/android/BOINC/app/src/main/AndroidManifest.xml index 2cc6b8524c..4878a57df4 100644 --- a/android/BOINC/app/src/main/AndroidManifest.xml +++ b/android/BOINC/app/src/main/AndroidManifest.xml @@ -19,9 +19,7 @@ --> + android:installLocation="internalOnly">