/android/app" /> /android/app" /> /android/app"/>

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

2.8k Views Asked by At

After adding the plugin webview_flutter_plus and after adding this line in android:usesCleartextTraffic="true" in your <project-directory>/android/app/src/main/AndroidManifest.xml under application

and Required Permissions line

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

I am facing the below error. Can anyone help me out to get this fixed?

Error :

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
3

There are 3 best solutions below

2
Jitesh Mohite On BEST ANSWER

If your minSdkVersion is set to 21 or higher, multidex is enabled by default and you do not need the multidex support library.

Below 21 API

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

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

Have you tried enabling multiDex in android folder -> app folder -> build.gradle file?

 defaultConfig {
        multiDexEnabled true
       
    }
1
Farid Istiqlal On

this happens because the library you are using uses the same dependences. in my case,i use package

flutter html : 1.0.0
youtube_player_flutter: ^6.1.0

and both packages use the same dependences, namely webview_flutter so that the error is

io.flutter.plugins.webviewflutter.WebViewFlutterPlugin

Solution

  1. in VSCode Search (Ctrl+Shift + P)
  2. in your error io.flutter.plugins.webviewflutter.WebViewFlutterPlugin search for keywords webview.
  3. Find a library that uses the same dependences, then update to the latest package version.(Work for me)
  4. This solution will keep the library you are using without deleting it.
flutter html : 1.0.0
youtube_player_flutter: ^7.0.0