17

I just import webview_flutter plugin and found that the plugin has incompatible with my flutter environment. Then using Android Studio I migrate my AndroidX environment with "Migrate to AndroidX" option.

I want to use webview_flutter plugin for viewing the page. Help appreciated.

Here is the error message

Launching lib/main.dart on Andromax B26D2H in debug mode...
D8: Program type already present: android.support.v4.media.MediaBrowserCompat$ItemCallback

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task
    ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/22.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/105.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/148.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/133.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/72.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/128.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/79.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/88.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/110.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/67.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/120.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/91.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/102.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/6.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/118.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/5.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/52.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/58.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/43.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/127.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/142.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/151.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/19.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/34.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/46.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/63.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/107.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/9.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/31.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/15.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/115.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/70.jar, /Users/tio/Documents/Development/firecek_2019/build/app/intermediates/transforms/dexBuilder/debug/62.jar,
    Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
    Program type already present: android.support.v4.media.MediaBrowserCompat$ItemCallback

  • 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 4m 59s ******************************************************************************************* The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.


Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

greybeard
  • 2,249
  • 8
  • 30
  • 66
Wisnu Wijokangko
  • 1,482
  • 1
  • 13
  • 15

11 Answers11

26

Thanks for your suggestion,

I've fixed it by doing these steps : 1. Try adding this line In your Project folder > android > app > build.gradle, add the following Line in

multiDexEnabled true

inside defaultConfig

  1. Then upgrade gradle dependency in the android/build.gradle file: classpath 'com.android.tools.build:gradle:3.3.1' (previously on version 3.2.1)

  2. Run flutter clean and rebuild your project

Wisnu Wijokangko
  • 1,482
  • 1
  • 13
  • 15
9

First make sure that all your packages in the pubspec.yaml are of the latest version. Then open the android project of your flutter app with android studio, select Refactor->Migrate to Androidx(make sure that you are doing that that from the android project and not from the flutter one). Wait until android studio finishes migrating your project, rebuild your project. Hope it helps!

Sami Kanafani
  • 14,244
  • 6
  • 45
  • 41
  • This works. However, it seems none of the files the migration tool changed, are caught by git (all files edited are within .gitignore). Would this fix still work for other team members? – WSBT May 06 '20 at 18:54
  • No other developers should run the migration – Sami Kanafani May 07 '20 at 06:23
4

I found this solution on Github by @tiklupxgit, solved this issue quickly.

Update this line in [Project Directory]/android/build.gradle

classpath 'com.android.tools.build:gradle:3.5.4'

Now run these commands in your terminal under [Project Directory]

flutter clean && flutter pub get

Finally, build your project again.

Abhishek Kumar
  • 738
  • 1
  • 9
  • 17
3

It seems like you are facing issues with dex and androidX.

Follow https://stackoverflow.com/a/56490440/9236994

this answer to resolve your issue.

Vicky Salunkhe
  • 9,869
  • 6
  • 42
  • 59
3

Create a new flutter project and move existing code to it: flutter migration

flutter create --androidx -t <project-type> <new-project-path>

eg: flutter create --androidx -t app .

Sujith Nair
  • 367
  • 3
  • 9
3

I have tried the best ever possible ways to break it down. I have been trying to use youtube videos from URL using the youtube video flutter plugin and getting androidx incompatibilities plugin error. Finally, I found the result. Just update

  1. the build.Gradle file in android - classpath 'com.android.tools.build:gradle:4.1.0'
  2. gradle-wrapper.properties

distributionUrl=https://services.Gradle.org/distributions/gradle-6.7-all.zip update the value as above it will work perfect, as for me.

Imran Rasheed
  • 825
  • 10
  • 25
Ansari Aadil
  • 135
  • 1
  • 2
1

For me, I copied settings.gradle file to the new file settings_aar.gradle

Then Removed the following code from settings_aar.gradle:

 def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
 def plugins = new Properties()
Islam Ahmed
  • 668
  • 9
  • 19
  • bro did you delete the settings.gradle file after copying it? bcz i have done this but mine issue was not resolved.. – Ismail Shah Jun 09 '21 at 06:49
1

Ok I finally solved the problem thanks to @Navpreet Singh

In order to fix the problem of the default grey icon of Firebase FCM (on Xiaomi devices) I added in the Manifest:

From then on, I got this error when building the application:

Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Completed 20,2s The build failed probably because of AndroidX incompatibilities in a plugin. The tool is about to try to use Jetifier to resolve the incompatibility. Building the cloud_firestore plugin... Exception: The cloud_firestore plugin could not be built because of the above problem. Running the Gradle task 'assembleAarRelease'...

When I commented out the metadata in the Manifest, the program started to compile again.

enter image description here

bulgarian-beast
  • 367
  • 3
  • 10
0

Just Enable multidex in app/build.gradle file.

defaultConfig {   
     ....
     multiDexEnabled true             
 }

dependencies {
    .....
    implementation 'com.android.support:multidex:2.0.1'
}
Niket Tongare
  • 553
  • 6
  • 7
0

You just only run 'get packages' in your pubspec.yaml and the probles will be solve

Carlos Peñaranda
  • 632
  • 1
  • 6
  • 19
-1

you can solve this issue by following these step which is given in this link

https://medium.com/@sahaishashank2507/the-gradle-failure-may-have-been-because-of-androidx-incompatibilities-in-this-flutter-app-39b34acee40e?source=---------2------------------

You need to open your project in the android studio.
select Refactor->Migrate to Androidx(You need to migrate Android Project not 
flutter one)
Android Studio finish some process you have to wait for it .
Than rebuild your project and it will work fine.

it can resolve your issue