Solve the problem of assembleDebug error (64K error) when the Flutter project is running without error

Solve the problem of assembleDebug error (64K error) when the project is running without error

Original: @As.Kai
Blog address: https://blog.csdn.net/qq_42362997
If the following content is helpful to you, please like it~

Error message:

* What went wrong:
Execution failed for task ':app:mergeDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
     The number of method references in a .dex file cannot exceed 64K.
     Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

We mainly look at this sentence
The number of method references in a .dex file cannot exceed 64K.

This error message roughly says:
The number of method references in a .dev file cannot exceed 64K.
Our project should refer to more dependent packages that exceed the official size of 64K, which
causes too many method references to cause errors.

When searching for related issues on the Internet, I found that:

The problem is with multidex builder. Actually, this often happens when you have imported a lot of packages in your yaml file which cannot fit into a single .dex built hence you have to enable multidex.

He probably means that because there are too many imported dependencies in the pubspec.yaml file that cannot be placed in a single .dex file, you must enable multidex for sub-packages.

solution:

Go to android/app/build.gradle and add the following lines of codes:
means go to android/app/build.gradle and add the following lines of codes :

dependencies {
  implementation 'com.android.support:multidex:1.0.3' //enter the latest version
}
android {
    defaultConfig {
        multiDexEnabled true
    }
}

Finally re-run the program, the problem is solved perfectly!

Don’t forget to like it~
Follow me and grow together!
@As.Kai

Guess you like

Origin blog.csdn.net/qq_42362997/article/details/113503385