Multidex issue with Flutter

前端 未结 7 1057
青春惊慌失措
青春惊慌失措 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:51

    In your app level build.gradle file

    1. Increase your minSdkVersion from 16 to 20.

    2. Enable multiDex.

      defaultConfig {
           ...
      
           minSdkVersion 20   //Copy this
           multiDexEnabled true //Copy this  
       }
      
    0 讨论(0)
  • 2020-11-27 17:51

    Just change the line in app\build.gradle

    defaultConfig{
    multiDexEnabled true
    }
    

    Do not add any dependencies I first added multidex dependencies but program said cannot find it I then added maven to build.gradle but made no change

    Actually you need to change false to true nothing else Android studio will do rest

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-27 18:03

    Your two packages seem to disagree on their transitive dependencies. One wants 11.6.+, the other wants 11.+ of some play-services dependencies. Since both 11.6.2 and 11.8.0 are out there, this is going to end up with a conflict.

    If you run ./gradlew androidDependencies in your android/ folder, you get a listing of the result of dependency resolution, containing, among others, the following:

    +--- :flutter_google_place_picker (variant: release)
    +--- com.google.android.gms:play-services-location:11.8.0@aar
    +--- com.google.android.gms:play-services-places:11.6.2@aar
    +--- com.google.android.gms:play-services-maps:11.6.2@aar
    +--- com.google.android.gms:play-services-base:11.8.0@aar
    +--- com.google.android.gms:play-services-tasks:11.8.0@aar
    +--- com.google.android.gms:play-services-basement:11.8.0@aar
    

    These 11.6.2 and 11.8.0 packages are not going to work together. To resolve this, you need to patch your dependencies to be consistent with each other, or add a dependency override to the top level of your android/app/build.gradle file and hope for the best:

    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-places:11.8.0'
            force 'com.google.android.gms:play-services-location:11.8.0'
        }
    }
    
    0 讨论(0)
  • 2020-11-27 18:03

    If you are installing via USB be sure to click on install button when the device asks for permission, It was the solution in my case.

    0 讨论(0)
  • 2020-11-27 18:04

    in your app folder inside android

    defaultConfig {
        ...
    
        multiDexEnabled true
    }
    

    Also check out: Enable multidex for apps with over 64K methods

    0 讨论(0)
提交回复
热议问题