Adding multiple flutter library modules fails build with duplicate class

197 Views Asked by At

Fail log

gw assembleDebug --scan

> Task :app:checkDebugDuplicateClasses FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class io.flutter.plugins.GeneratedPluginRegistrant found in modules flutter_debug-1.0-runtime (com.example.a.library_a:flutter_debug:1.0) and flutter_debug-2.0-runtime (com.example.b.library_b:flutter_debug:2.0)

     Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

Steps to reproduce;

flutter create -t module --org com.example.a library_a
cd library_a
flutter pub add android_intent_plus
flutter build aar

cd ..

flutter create -t module --org com.example.b library_b
cd library_a
flutter pub add android_intent_plus
// Open pubspec.yaml and change android_intent_plus to 1.0.1
flutter build aar --build-number=2.0

Add both library_a and library_b to an android project. (I tested with a new project)

Build fails with duplicate class.

flutter doctor;

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.5.1 21G83 darwin-arm, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio
    ✗ Unable to find bundled Java version.
[!] Android Studio
    ✗ Unable to find bundled Java version.
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.3)
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
[✓] VS Code (version 1.74.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
0

There are 0 best solutions below