3

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

  • No, you just need to extend FlutterApplication and then add `@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }` and then specify your own application class in the androidmanifest – EpicPandaForce Dec 12 '18 at 10:43
  • @EpicPandaForce I am unable to make changes in `FlutterApplication` class. it is decompiled version. So, the file is not writable. –  Dec 12 '18 at 10:51

1 Answers1

4

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" .../>
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • The only incorrect thing here was that "this is not a good solution". No, it is the correct solution. – EpicPandaForce Dec 12 '18 at 12:53
  • @EpicPandaForce Thank you so much, I thought I might not be, but now you say, so I am confident using it in my app. –  Dec 12 '18 at 13:33
  • I just hit this gotcha. Please where do I place this snippet, I mean this class? – Wale Feb 09 '19 at 13:54
  • @Wale You need to put this in your `android>app>src>main>java>package_name` –  Feb 11 '19 at 14:09
  • i got this error `\Application.java:15: error: package androidx.multidex does not exist import androidx.multidex.MultiDex;` any ideas about this? – Simou Nov 23 '20 at 21:32
  • 1
    @Simou, Try to put `implementation 'com.android.support:multidex:1.0.3'` into `dependencies` section of build.gradle file under app folder, then import `androidx.multidex.MultiDex;` in your application class file. – Capt. Michael Mar 27 '21 at 12:39