Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve duplicate classes issue for Flutter?

after adding

location: ^1.4.1

to my dependencies in pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  rxdart: ^0.20.0
  http: ^0.12.0
  date_format: ^1.0.5
  intl: ^0.15.7
  fluttertoast: ^2.2.3
  location: ^1.4.1

I do Packages get, and everything is fine, but when I try to build it, the app crashes with a message:

Launching lib\main.dart on Lenovo K33a48 in debug mode... Initializing gradle... Resolving dependencies... Gradle task 'assembleDebug'... D8: Program type already present: android.support.v4.app.INotificationSideChannel

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: "Here goes the list of all jar archives" Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.app.INotificationSideChannel

  • 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 18s Finished with error: Gradle task assembleDebug failed with exit code 1

My targetSdk is 28. I use Android Studio 3.2.1 Help would be very much appreciated!

like image 752
miloss Avatar asked May 04 '26 10:05

miloss


1 Answers

this happens because the library you are using uses the same dependences.

SOLUTION 1

  1. in VSCode Search (Ctrl+Shift + P)
  2. in your error android.support.v4.app.INotificationSideChannel. search for keywords Notification/Side/Channel. pick one.
  3. If there are the same dependences, it means that there are duplicate libraries.
  4. Solution: Delete one of the libraries you are using

SOLUTION 2 (Recommended)

  1. in VSCode Search (Ctrl+Shift + P)
  2. in your error android.support.v4.app.INotificationSideChannel. search for keywords Notification/Side/Channel. pick one.
  3. Find a library that uses the same dependences, then update to the latest package version.
  4. This solution will keep the library you are using without deleting it
like image 181
Farid Istiqlal Avatar answered May 05 '26 23:05

Farid Istiqlal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!