App Requires Multidex Support Flutter

When your App surpasses the 65536 methods in, it gives a build error, which shows that your app has exceeded the limit of references that can be invoked in a single DEX file. for avoiding the problem you need to enable multidex, which allows your app to make and read multiple DEX files. 

How to Enable Multidex Support in Flutter:

If your minSdkVersion is 21 or higher, multidex is enabled by default because it uses ART which supports multidexing. But, if your minSdkVersion is set to 20 or lower, then you have to use the multidex library.

1. In the module-level build.gradle file, we have to enable multidex and add the multidex library :

...
android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 // lower than 20, so it doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled tru
         }
}

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

2. Based upon whether you override the Application class, do any of the following steps:

  • If you have not overridden the Application class in your App Then, edit your manifest file to set android:name in the <application> tag as follows:

...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="androidx.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>
...

  • If you have overridden the Application class, change it to extend MultiDexApplication (if possible) as follows:

...
public class Application extends MultiDexApplication {

}
...

  • Or if you do override the Application class but you don’t want to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

...
public class YouApplication extends Application {

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

}
...

For more information, you can go to the official documentation of Multidex.

Thanks for reading! if you are interested in App development check out our other Articles as well.

Leave a Comment

Your email address will not be published.