Bug 1285511 - Add multidex support to automation builds. r=sebastian, a=gchang
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 20 Jul 2016 13:06:40 -0700
changeset 342070 fb657c8ddd979b7a23f6b626497416513a0b3941
parent 342069 2d8d82f4786b72de0bb98a4cbae63ed53f1a6d02
child 342071 20744b466321494e6d751f68d956e94c14081244
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1285511
milestone49.0a2
Bug 1285511 - Add multidex support to automation builds. r=sebastian, a=gchang I initially tested my code with a branch around the multidex dependency: if (mozconfig.substs.MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE) { compile ...multidex... } I removed it because it seemed unnecessary - the code shouldn't be included if it's not referenced. I tested: * Locally with a build that did not exceed the method limit, pre-Lollipop * On try, with fx-team * On try, with beta MozReview-Commit-ID: APaOdlKd3QF
mobile/android/app/build.gradle
mobile/android/base/AppConstants.java.in
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -48,26 +48,40 @@ android {
         // 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.
             minSdkVersion 21
             dexOptions {
                 preDexLibraries true
+                // We only call `MultiDex.install()` for the automation build flavor
+                // so this may not work. However, I don't think the multidex support
+                // library is necessary for 21+, so I expect that it will work.
                 multiDexEnabled true
             }
         }
         // For API < 21 - does not support multi dex because local development
         // is slow in that case. Most builds will not require multi dex so this
         // should not be an issue.
         localOld {
         }
         // Automation builds.
         automation {
+            dexOptions {
+                // As of FF48 on beta, the "test", "lint", etc. treeherder jobs fail because they
+                // exceed the method limit. Beta includes Adjust and its GPS dependencies, which
+                // increase the method count & explain the failures. Furthermore, this error only
+                // occurs on debug builds because we don't proguard.
+                //
+                // We enable multidex as an easy, quick-fix with minimal side effects but before we
+                // move to gradle for our production builds, we should re-evaluate this decision
+                // (bug 1286677).
+                multiDexEnabled true
+            }
         }
     }
 
     sourceSets {
         main {
             manifest.srcFile "${project.buildDir}/generated/source/preprocessed_manifest/AndroidManifest.xml"
 
             java {
@@ -166,16 +180,18 @@ android {
             // we have tests that start test servers and the bound ports
             // collide.  We'll fix this soon to have much faster test cycles.
             maxParallelForks 1
         }
     }
 }
 
 dependencies {
+    compile 'com.android.support:multidex:1.0.0'
+
     compile "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
     compile "com.android.support:appcompat-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
     compile "com.android.support:cardview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
     compile "com.android.support:recyclerview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
     compile "com.android.support:design:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
 
     if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
         compile "com.android.support:mediarouter-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -1,17 +1,21 @@
 //#filter substitution
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import android.content.Context;
 import android.os.Build;
+//#ifdef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
+import android.support.multidex.MultiDex;
+//#endif
 
 /**
  * A collection of constants that pertain to the build and runtime state of the
  * application. Typically these are sourced from build-time definitions (see
  * Makefile.in). This is a Java-side substitute for nsIXULAppInfo, amongst
  * other things.
  *
  * See also SysInfo.java, which includes some of the values available from
@@ -331,9 +335,26 @@ public class AppConstants {
 //#ifdef MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE
     true;
 //#else
     false;
 //#endif
 
     // (bug 1266820) Temporarily disabled since no one is working on it.
     public static final boolean SCREENSHOTS_IN_BOOKMARKS_ENABLED = false;
+
+    /**
+     * Enables multidex depending on build flags. For more information,
+     * see `multiDexEnabled true` in mobile/android/app/build.gradle.
+     *
+     * As a method, this shouldn't be in AppConstants, but it's
+     * the only semi-relevant Java file that we pre-process.
+     */
+    public static void maybeInstallMultiDex(final Context context) {
+//#ifdef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
+        if (BuildConfig.FLAVOR.equals("automation")) {
+            MultiDex.install(context);
+        }
+//#else
+        // Do nothing.
+//#endif
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -134,16 +134,22 @@ public class GeckoApplication extends Ap
         final Context applicationContext = getApplicationContext();
         GeckoBatteryManager.getInstance().start(applicationContext);
         GeckoNetworkManager.getInstance().start();
 
         mInBackground = false;
     }
 
     @Override
+    protected void attachBaseContext(Context base) {
+        super.attachBaseContext(base);
+        AppConstants.maybeInstallMultiDex(base);
+    }
+
+    @Override
     public void onCreate() {
         Log.i(LOG_TAG, "zerdatime " + SystemClock.uptimeMillis() + " - Fennec application start");
 
         mRefWatcher = LeakCanary.install(this);
 
         final Context context = getApplicationContext();
         HardwareUtils.init(context);
         Clipboard.init(context);