Bug 1255914 - Part 1: Proguard (minify) Gradle builds in automation. r=sebastian
authorNick Alexander <nalexander@mozilla.com>
Mon, 21 Nov 2016 11:58:57 -0800
changeset 323622 61e649e690c9073c07d70b4d5fccbcc40855ceeb
parent 323621 e20c0b78111ecd40826a7caa5a141fe9c3519a98
child 323623 a776c56e2ac7879f8e910cd616da0fcf0379a970
push id34475
push usernalexander@mozilla.com
push dateMon, 21 Nov 2016 20:05:45 +0000
treeherderautoland@a776c56e2ac7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
--- 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.