Multidex issue with Flutter

前端 未结 7 1166
青春惊慌失措
青春惊慌失措 2020-11-27 17:35

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         


        
7条回答
  •  借酒劲吻你
    2020-11-27 17:55

    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:

    1. Open your "app level build.gradle file" which exists at [your project]\android\app\build.gradle

    2. 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.

提交回复
热议问题