including .apk signing, and turn on proguard, for release gradle builds

This commit is contained in:
Eric House 2015-11-18 06:27:11 -08:00
parent e0cb84a332
commit dc5b979e8a
2 changed files with 60 additions and 8 deletions

View file

@ -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"
}
}

View file

@ -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 *; }