Bug 1255914 - Part 1: Proguard (minify) Gradle builds in automation. r=sebastian draft
authorNick Alexander <nalexander@mozilla.com>
Mon, 21 Nov 2016 11:58:57 -0800
changeset 442130 dfc0f983f56ceb5907f9aafcb37d2ac63d50988b
parent 441717 15b756d777d4b79db8dcc79f1aff59a8dfea9ab2
child 442131 cdfb01a47dc05dfafc4ba67cdb30f86dbd5aa4ec
push id36592
push usernalexander@mozilla.com
push dateMon, 21 Nov 2016 20:02:36 +0000
reviewerssebastian
bugs1255914
milestone53.0a1
Bug 1255914 - Part 1: Proguard (minify) Gradle builds in automation. r=sebastian moz.build achieves better results than Gradle, and I can't fully explain why that is. At first I thought it was due to -optimizationpasses, which is 6 for MOZILLA_OFFICIAL; however, it's not -- I see no change (let alone an improvement), when I set the number of passes to 1, 6, 10, or 100. I think there are two things at play. First, moz.build strips debugging information from "libraries", which are broadly the Google support libraries. I don't think it's possible to strip debug information in this fine-grained manner using Gradle. Second, I think the Gradle build might be including more code than the moz.build configuration (see the follow-up patch removing multidex support), but I can't determine what's actually different. After APK compression, I see less than a 50kb regression in APK size between Gradle and moz.build outputs, which I deem reasonable. MozReview-Commit-ID: 4q4Zye2wnOF
mobile/android/app/build.gradle
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -39,21 +39,42 @@ android {
         javaMaxHeapSize "2g"
     }
 
     lintOptions {
         abortOnError true
     }
 
     buildTypes {
-        release {
-            shrinkResources true
+        // We have the following difficult situation.  Minification (Proguard) is only available per
+        // Android-Gradle `buildType`.  Instrumentation (Robocop) is only available for exactly one
+        // `buildType` (see Android-Gradle `testBuildType`, which defaults to "debug").  Local
+        // developers expect to build and run tests against the "debug" build type.  Automation
+        // needs to produce an instrumentation (Robocop) APK against a Fennec APK that will ship.
+        // (This is very unusual; usually, instrumentation tests do _not_ run against a shipping
+        // APK.)
+        //
+        // Given these constraints, we should not change `testBuildType` to avoid confusing local
+        // developers.  Also, we should not Proguard any "debug" builds, because we don't want local
+        // developers to incur the cost of Proguard.  However, we still need to find a way to
+        // Proguard a shipping APK and produce an instrumentation (Robocop APK) against it.  To
+        // achieve this, we make "debug" builds Proguard in automation alone.  This does have the
+        // unfortunate side effect of Proguarding the instrumentation (Robocop) APK, but nothing
+        // uses runtime inspection or class-loading with that APK, so it shouldn't be a problem.
+        def configureMinifyClosure = {
+            // Bug 1229269: we can't yet shrinkResources effectively.  Be sure
+            // to use -stripped.ap_ after enabling this.
+            // shrinkResources true
             minifyEnabled true
             proguardFile "${topsrcdir}/mobile/android/config/proguard/proguard.cfg"
         }
+        release configureMinifyClosure
+        if (mozconfig.substs.MOZILLA_OFFICIAL) {
+            debug configureMinifyClosure
+        }
     }
 
     productFlavors {
         // For API 21+ - with multi dex, this will be faster for local development.
         local {
             // For multi dex, setting `minSdkVersion 21` allows the Android gradle plugin to
             // pre-DEX each module and produce an APK that can be tested on
             // Android Lollipop without time consuming DEX merging processes.