Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter project exceeds .dex Method Reference Count limit

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)

like image 655
creativecreatorormaybenot Avatar asked Jul 24 '18 00:07

creativecreatorormaybenot


People also ask

How many methods can be referenced from a single DEX file?

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.

How do I enable multidex in flutter project?

Starting from Flutter 2.10 The multidex support is enabled automatically. If your app supports Android SDK versions below 21, and it exceeds the 64K method limit, simply pass the --multidex flag to flutter build appbundle or flutter build apk and your app will support multidex. Save this answer.

What is multidex enabled?

Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.


1 Answers

I had 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"     } 
like image 167
Omar Ali Avatar answered Sep 21 '22 15:09

Omar Ali