How to Enable Multidexing With the New Android Multidex Support Library

How to enable multidexing with the new Android Multidex support library

Edit:

Android 5.0 (API level 21) and higher uses ART which supports multidexing. Therefore, if your minSdkVersion is 21 or higher, the multidex support library is not needed.


Modify your build.gradle:

android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22

// Enabling multidex support.
multiDexEnabled true
}
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
}

If you are running unit tests, you will want to include this in your Application class:

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

}

Or just make your application class extend MultiDexApplication

public class Application extends MultiDexApplication {

}

For more info, this is a good guide.

Enabling MultiDex Support in Android to achieve 65K+ methods in Eclipse

You have to modify build.gradle to add multiDexEnabled true under buildconfig, buildType or productFlavour sections

defaultConfig {
// The support library goes as back as Android-14, and is not required for 21+
minSdkVersion 14

// Enabling multidex support.
multiDexEnabled true
}

If you're building on old Ant, this is a blocking problem so you'll have to move to gradle or maven or use the old cumbersome solution

http://android-developers.blogspot.com.es/2011/07/custom-class-loading-in-dalvik.html

Multidex issue with Flutter

Your two packages seem to disagree on their transitive dependencies. One wants 11.6.+, the other wants 11.+ of some play-services dependencies. Since both 11.6.2 and 11.8.0 are out there, this is going to end up with a conflict.

If you run ./gradlew androidDependencies in your android/ folder, you get a listing of the result of dependency resolution, containing, among others, the following:

+--- :flutter_google_place_picker (variant: release)
+--- com.google.android.gms:play-services-location:11.8.0@aar
+--- com.google.android.gms:play-services-places:11.6.2@aar
+--- com.google.android.gms:play-services-maps:11.6.2@aar
+--- com.google.android.gms:play-services-base:11.8.0@aar
+--- com.google.android.gms:play-services-tasks:11.8.0@aar
+--- com.google.android.gms:play-services-basement:11.8.0@aar

These 11.6.2 and 11.8.0 packages are not going to work together. To resolve this, you need to patch your dependencies to be consistent with each other, or add a dependency override to the top level of your android/app/build.gradle file and hope for the best:

configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-places:11.8.0'
force 'com.google.android.gms:play-services-location:11.8.0'
}
}

Flutter enable multiDex for SDK less than 21

Actually I need to create my own java class say MyApplication.java like this.

public class MyApplication extends FlutterApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

After this in AndroidManifest.xml file, change

<application
android:name="io.flutter.app.FlutterApplication" .../>

to

<application
android:name=".MyApplication" .../>

Android support Multidex still generates the 'over than 64K methods in main-dex file' error

According to documentation you must have in your multidex-config the classes you want to keep.

Analyze your APK and check for the classes and methods there are included on the main dex file and check the packages that are contributing the reach the 64K limit.

Make sure you are not keeping your entire project on the multidex-config file.

The example given in the documentation can be misleading if you use a broad package filter:

-keep class com.example.** { *; }

Try to keep only necessary packages:

-keep class com.example.YOUR-PACKAGE** { *; }

What is Android MultiDex?

Quoting the documentation:

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

So, the feature is: it allows your complex app to compile. The scenarios for using it are when your app fails to compile due to hitting the 64K DEX method reference limit. This appears as a build error, such as:

Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536


Related Topics



Leave a reply



Submit