Wisnu Wijokangko
Wisnu Wijokangko

Reputation: 2318

How to fix flutter AndroidX incompatibility?

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)

Upvotes: 17

Views: 64194

Answers (11)

Carlos Peñaranda
Carlos Peñaranda

Reputation: 783

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

Upvotes: 0

Ansari Aadil
Ansari Aadil

Reputation: 165

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.

Upvotes: 3

Niket Tongare
Niket Tongare

Reputation: 632

Just Enable multidex in app/build.gradle file.

defaultConfig {   
     ....
     multiDexEnabled true             
 }

dependencies {
    .....
    implementation 'com.android.support:multidex:2.0.1'
}

Upvotes: 0

Abhishek Kumar
Abhishek Kumar

Reputation: 832

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.

Upvotes: 4

bulgarian-beast
bulgarian-beast

Reputation: 425

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

Upvotes: 1

Islam Ahmed
Islam Ahmed

Reputation: 756

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()

Upvotes: 1

Shashank Sahai
Shashank Sahai

Reputation: 107

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

Upvotes: -1

Sujith Nair
Sujith Nair

Reputation: 387

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 .

Upvotes: 3

Wisnu Wijokangko
Wisnu Wijokangko

Reputation: 2318

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

Upvotes: 26

Vicky Salunkhe
Vicky Salunkhe

Reputation: 11025

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

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

this answer to resolve your issue.

Upvotes: 3

Sami Kanafani
Sami Kanafani

Reputation: 15751

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!

Upvotes: 9

Related Questions