From dc5b979e8a28225370be7d586cb61636bfd4ff68 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 18 Nov 2015 06:27:11 -0800 Subject: [PATCH] including .apk signing, and turn on proguard, for release gradle builds --- xwords4/android/XWords4/app/build.gradle | 51 ++++++++++++++++--- .../android/XWords4/app/proguard-rules.pro | 17 +++++++ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/xwords4/android/XWords4/app/build.gradle b/xwords4/android/XWords4/app/build.gradle index a1066ef71..be3fb36ea 100644 --- a/xwords4/android/XWords4/app/build.gradle +++ b/xwords4/android/XWords4/app/build.gradle @@ -34,20 +34,28 @@ android { targetSdkVersion 14 } + signingConfigs { + release { + storeFile file(System.getenv("HOME") + "/.keystore") + keyAlias "mykey" + + // These two lines make gradle believe that the signingConfigs + // section is complete. Without them, tasks like installRelease + // will not be available! + storePassword "notReal" + keyPassword "notReal" + } + } + buildTypes { release { - minifyEnabled false + signingConfig signingConfigs.release + debuggable false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true - applicationVariants.all { variant -> - variant.outputs.each { output -> - def versionName = getVersionName() - versionName = "XWords4-debug-" + versionName + ".apk" - output.outputFile = new File(output.outputFile.parent, versionName) - } - } } } @@ -134,3 +142,30 @@ afterEvaluate { compileReleaseNdk.dependsOn ndkBuildRelease compileDebugNdk.dependsOn ndkBuildDebug } + +task askForPassword << { + def password = System.getenv("ANDROID_KEY_PASS") + if (null == password || 0 == password.length()) { + if ( null != System.console() ) { + password = new String(System.console() + .readPassword("ANDROID_KEY_PASS not set; " + + "Keystore password: ")) + } else { + password = null + println( "ANDROID_KEY_PASS not set and no console; " ) + println( "sign it yerself later. (Or you might try" ) + println( " running gradlew with the --no-daemon flag)" ) + } + } + + if ( null != password ) { + android.signingConfigs.release.storePassword = password + android.signingConfigs.release.keyPassword = password + } +} + +tasks.whenTaskAdded { theTask -> + if (theTask.name.equals("packageRelease")) { + theTask.dependsOn "askForPassword" + } +} diff --git a/xwords4/android/XWords4/app/proguard-rules.pro b/xwords4/android/XWords4/app/proguard-rules.pro index 55f1c8742..9f4fe14b6 100644 --- a/xwords4/android/XWords4/app/proguard-rules.pro +++ b/xwords4/android/XWords4/app/proguard-rules.pro @@ -15,3 +15,20 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} + +# Keep everything. Useful maybe for confirming that proguard's causing +# a problem? +# -keep class ** { *; } + +# Don't turn this on until it's clear that proguard isn't messing +# anything else up. It'll make crash reports useless. + +-dontobfuscate + +# Uncomment this if obfuscation is enabled (by removing the line +# above), and save the mapping.txt file or confirm it can be rebuilt +# from a tag. +# -keepattributes SourceFile,LineNumberTable + +# Prevents crash when jni code calls setInt on various jin.* classes +-keep public class org.eehouse.android.xw4.jni.** { public *; }