How to fix flutter AndroidX incompatibility?

58,467

Solution 1

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

Solution 2

To summarize the changes that fixed the problem:

Enable multidex.

Go to [project_folder]/app/build.gradle and add following lines.

defaultConfig {
    ...
    multiDexEnabled true
}

Enable Jetifier.

Go to [project_folder]/android/app/gradle.properties and add following lines.

android.useAndroidX=true
android.enableJetifier=true

Solution 3

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!

Solution 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.

Solution 5

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 .

Share:
58,467
Wisnu Wijokangko
Author by

Wisnu Wijokangko

Updated on July 25, 2022

Comments

  • Wisnu Wijokangko
    Wisnu Wijokangko almost 2 years

    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)

  • WSBT
    WSBT about 4 years
    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?
  • Sami Kanafani
    Sami Kanafani about 4 years
    No other developers should run the migration
  • bulgarian-beast
    bulgarian-beast about 3 years
    I don't really understand why this is happening, but I hope my answer will help
  • Ismail Shah
    Ismail Shah almost 3 years
    bro did you delete the settings.gradle file after copying it? bcz i have done this but mine issue was not resolved..