Bug 1468487 - Enable multidex for local builds; r?nalexander
MozReview-Commit-ID: BEQmkKajTxF
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -216,16 +216,21 @@ dependencies {
implementation "com.android.support:support-v4:$support_library_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support:cardview-v7:$support_library_version"
implementation "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:design:$support_library_version"
implementation "com.android.support:customtabs:$support_library_version"
implementation "com.android.support:palette-v7:$support_library_version"
+ // We always include support for multidexing even when we don't enable it at runtime.
+ // We could conditionally include support, but we'd need
+ // to generate the `Application` class or fork the file on disk.
+ implementation "com.android.support:multidex:1.0.3"
+
if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
implementation "com.android.support:mediarouter-v7:$support_library_version"
implementation "com.google.android.gms:play-services-basement:$google_play_services_version"
implementation "com.google.android.gms:play-services-base:$google_play_services_version"
implementation "com.google.android.gms:play-services-cast:$google_play_services_version"
}
if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -16,16 +16,17 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Process;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
+import android.support.multidex.MultiDex;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import org.mozilla.gecko.annotation.WrapForJNI;
@@ -363,16 +364,32 @@ public class GeckoApplication extends Ap
"Bookmark:Insert",
"Image:SetAs",
"Profile:Create",
null);
super.onCreate();
}
+ @Override
+ protected void attachBaseContext(Context base) {
+ super.attachBaseContext(base);
+
+ // Enable multiDex only for local builds.
+ final boolean isLocalBuild = BuildConfig.FLAVOR_audience.equals("local");
+
+ // API >= 21 natively supports loading multiple DEX files from APK files.
+ // Needs just 'multiDexEnabled true' inside the gradle build configuration.
+ final boolean isMultidexLibNeeded = BuildConfig.FLAVOR_minApi.equals("noMinApi");
+
+ if (isLocalBuild && isMultidexLibNeeded) {
+ MultiDex.install(this);
+ }
+ }
+
/**
* May be called when a new GeckoApplication object
* replaces an old one due to assets change.
*/
private void onDestroy() {
EventDispatcher.getInstance().unregisterGeckoThreadListener(mListener,
"Distribution:GetDirectories",
null);
--- a/mobile/android/gradle/product_flavors.gradle
+++ b/mobile/android/gradle/product_flavors.gradle
@@ -3,16 +3,17 @@
* 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/. */
ext.configureProductFlavors = {
flavorDimensions "audience", "geckoBinaries", "minApi"
productFlavors {
local {
dimension "audience"
+ multiDexEnabled true
}
// Automation builds. We use "official" rather than "automation" to drive these builds down
// the list of configurations that Android Studio offers, thereby making it _not_ the
// default. This avoids a common issue with "omni.ja" not being packed into the default APK
// built and deployed by Android Studio.
official {
dimension "audience"