I\'m getting the following error compiling with gradle using Flutter in Android Studio:
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexExce
Update for beginner devs in 2020:
If you're OK with setting the minimum required Android API level as high as 21 (your app will still run on 94.1% of devices as of this writing), then all you have to do is this:
Open your "app level build.gradle file" which exists at [your project]\android\app\build.gradle
Change the 16 (or whatever number it is for you) to at least a 21:
defaultConfig {
// ...
minSdkVersion 16
// ...
}
... to:
defaultConfig {
// ...
minSdkVersion 21
// ...
}
You don't have to make ANY other modifications in order for multidex to work correctly.
Apparently, the default minSDK setting for new Flutter projects is 16, so after adding enough dependencies in pubspec.yaml, many new developers will run into the multidex error and go searching online, potentially getting bogged down in confusing information which only applies to projects with a minimum level set to less than 21.