Home » Android » android – Flutter project exceeds .dex Method Reference Count limit

android – Flutter project exceeds .dex Method Reference Count limit

Posted by: admin June 15, 2020 Leave a comment

Questions:

Why does a Flutter project exceed 64K method reference in its .dex file?

I am wondering what the cause of this could be:
In a rather small Flutter project I use 13 plugins. Without Multidex, the Android build fails because it vastly exceeds the method reference limit.

Is there any trick (e.g. Gradle related) that would allow to shrink the method reference count because I think that such a project should not exceed the limit?
(if you want further information on why I think that this is odd, please take a look at older revisions of this question)

How to&Answers:

Use ProGuard to eliminate unused classes at compile time. This will reduce your method count by a considerable amount.

You will need to adjust the ProGuard rules to work with Flutter like the Flutter documentation explains here.

Answer:

in your android/app/build file increase the minsdkversion from 16 to 21 under defautConfig.
Some have even increased it to 28 but it worked for me at 21.
Here is the link to the issue on git

Edit: multiDexEnabled: true also works for some under the same defautConfig.

Answer:

i hade the same problem and the fix for me was increasing the minSdkVersion in the app/build.bradle like this

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        minSdkVersion 21 // change this to 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Answer:

I successfully migrated the app to androidx using the below link and the second step:

1) Flutter Projects & Android X Migration Issues

2) In your android/app/build file increase the minsdkversion from 16 to 21 under defaultConfig. Some have even increased it to 28 but it worked for me at 21.