Bug 1285511 - Add multidex support to automation builds. r=sebastian
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 20 Jul 2016 13:06:40 -0700
changeset 346337 6972bef6693c9a78d5e7bb45722fd4990d517f1d
parent 346336 04533ff743455eb7ecdf1aa5fcf4f9935bf54d12
child 346338 ff29f08b72c466b65dea5efa6f82f99add8f17ef
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1285511
milestone50.0a1
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 1285511 - Add multidex support to automation builds. r=sebastian 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}"
     compile "com.android.support:customtabs:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
 
     if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
--- 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
@@ -338,9 +342,26 @@ public class AppConstants {
 //#ifdef MOZ_ANDROID_CUSTOM_TABS
     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);