From bcb91d87db014aeced5d0747d620a6a1d0b2270b Mon Sep 17 00:00:00 2001 From: Lennart Goedhart Date: Sun, 22 May 2016 14:42:25 +1000 Subject: [PATCH] More grade release automation work for #15 --- app/app.iml | 4 +- app/build.gradle | 62 ++++++++++++++++++++++++++++ app/gradle.properties | 2 +- app/src/main/AndroidManifest.xml | 3 +- app/src/main/res/values/strings.xml | 1 - app/src/main/res/xml/preferences.xml | 2 +- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/app/app.iml b/app/app.iml index 2b5e236..f00cf65 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -106,6 +106,8 @@ + + diff --git a/app/build.gradle b/app/build.gradle index 98bf251..d1bc88b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,14 +4,25 @@ plugins { apply plugin: 'com.android.application' +def gitVersion() { + def process = ['sh', '-c', 'git tag -l | grep -c ".*" -'].execute().text.trim() + return process.toInteger() + 1 +} + android { compileSdkVersion 21 buildToolsVersion "23.0.3" + applicationVariants.all { variant -> + variant.resValue "string", "versionName", variant.versionName + } + defaultConfig { applicationId "info.nightscout.android" minSdkVersion 15 targetSdkVersion 21 + versionName project.properties['version'] + versionCode gitVersion() } buildTypes { @@ -28,8 +39,59 @@ android { } } +task signRelease << { + def command = [ + 'jarsigner', + '-verbose', + '-sigalg', + 'SHA1withRSA', + '-digestalg', + 'SHA1', + '-keystore', + '/Users/lgoedhart/keystores/nightscout_android.jks', + 'app/build/outputs/apk/app-release-unsigned.apk', + 'nightscoutandroidkey' + ] + + def proc = new ProcessBuilder(command) + .redirectOutput(ProcessBuilder.Redirect.INHERIT) + .redirectInput(ProcessBuilder.Redirect.INHERIT) + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start() + + proc.waitFor() + + if (0 != proc.exitValue()) { + throw new RuntimeException("Could not sign APK.") + } +} + +task zipalignRelease << { + def command = [ + '/Users/lgoedhart/Library/Android/sdk/build-tools/23.0.3/zipalign', + '-v', + '4', + 'app/build/outputs/apk/app-release-unsigned.apk', + 'app/build/outputs/apk/640g-android-uploader.apk' + ] + + def proc = new ProcessBuilder(command) + .redirectOutput(ProcessBuilder.Redirect.INHERIT) + .redirectInput(ProcessBuilder.Redirect.INHERIT) + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start() + + proc.waitFor() + + if (0 != proc.exitValue()) { + throw new RuntimeException("Could not align APK.") + } +} + release { tagTemplate = 'v${version}' + buildTasks = ['assembleRelease'] + afterReleaseBuild.dependsOn 'signRelease', 'zipalignRelease' } dependencies { diff --git a/app/gradle.properties b/app/gradle.properties index ac7979d..6324588 100644 --- a/app/gradle.properties +++ b/app/gradle.properties @@ -1 +1 @@ -version=0.2.1 \ No newline at end of file +version=0.2.0-SNAPSHOT diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9b3a7d6..1f9b4a4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,7 @@ + > Disclaimer Accept Refuse - 0.2.0