Flutter - 任务 ':app:multiDexListDebug' 执行失败

Flutter - Execution failed for task ':app:multiDexListDebug'

添加插件后 webview_flutter_plus 并在 android:usesCleartextTraffic="true" in your <project-directory>/android/app/src/main/AndroidManifest.xml under application 中添加此行后

和所需权限行

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

我遇到了以下错误。谁能帮我解决这个问题?

错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:multiDexListDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Error while merging dex archives: 
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Type io.flutter.plugins.webviewflutter.WebViewFlutterPlugin is defined multiple times: C:\Users\Admin\Downloads\flow-0.1-master\build\webview_media\intermediates\runtime_library_classes\debug\classes.jar:io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.class, C:\Users\Admin\Downloads\flow-0.1-master\build\webview_flutter\intermediates\runtime_library_classes\debug\classes.jar:io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 47s
Exception: Gradle task assembleDebug failed with exit code 1

您是否尝试在 android 文件夹 -> 应用程序文件夹 -> build.gradle 文件中启用 multiDex?

 defaultConfig {
        multiDexEnabled true
       
    }

如果您的 minSdkVersion 设置为 21 或更高,multidex 是默认启用的,您不需要 multidex 支持库。

21岁以下API

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3' // add latest dependency
}

发生这种情况是因为您正在使用的库使用相同的依赖项。 就我而言,我使用 package

flutter html : 1.0.0
youtube_player_flutter: ^6.1.0

并且两个包使用相同的依赖,即webview_flutter所以错误是

io.flutter.plugins.webviewflutter.WebViewFlutterPlugin

解决方案

  1. 在VSCode中搜索(Ctrl+Shift + P)
  2. 在您的错误中 io.flutter.plugins.webviewflutter.WebViewFlutterPlugin 搜索关键字 webview。
  3. 找到一个使用相同依赖的库,然后更新到latest package version。(为我工作)
  4. 此解决方案将保留您正在使用的库而不删除它。
flutter html : 1.0.0
youtube_player_flutter: ^7.0.0