Search code examples
androiddartflutterandroid-multidex

Flutter enable multiDex for SDK less than 21


How can I enable multiDex for SDK less than 21. This page shows how to do it, but it says for API less 21.

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication { ... }

So, in Flutter, my application by default overrides io.flutter.app.FlutterApplication and I should make changes in my FlutterApplication class but I couldn't open this file for editing because it is decompiled version. Can anyone help me? It is an issue on Github


Solution

  • 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" .../>