1

We've an Android project with many modules, including dynamic feature modules. The build script boilerplate is currently handled by using script plugins (Gradle files that are applied by using apply from: 'something.gradle').

I am trying to migrate the script plugins to become build convention plugins, either buildSrc/ or an included build (includeBuild 'build-conventions') so that it can be applied by using plugin DSL (plugins { id 'mybuild.something-convention' }). However it fails when running ./gradlew bundleDebug saying that the base module and one of the dynamic feature modules both contain the same entry (struct.proto) with different content.

* What went wrong:
Execution failed for task ':app:packageDebugBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.PackageBundleTask$BundleToolWorkAction
   > Modules 'base' and '‹dynamicfeature1›' contain entry 'root/google/protobuf/struct.proto' with different content.

Please help me. I am trying to figure out and so far get these clues:

  • ./gradlew <module>:dependencies --configuration debugRuntimeClasspath shows that the base module and the dynamic feature module have different version of com.google.protobuf:protobuf-javalite dependency. This is also the case before migrating to build convention plugins, but the resulting AAB of the dynamic feature module did not contain struct.proto entry then, so that there was no duplicate entry. Illustration of the indirect graph:

    # In both module:
    com.google.firebase:firebase-bom:30.3.1
    └> com.google.firebase:firebase-perf-ktx:20.1.0 (c)
    └> com.google.firebase:firebase-firestore:24.2.1 (c)
    
    # In base module:
    com.google.firebase:firebase-perf-ktx:20.1.0
    └> com.google.protobuf:protobuf-javalite:3.17.3
    
    # In dynamic feature module:
    com.google.firebase:firebase-perf-ktx:20.1.0
    └> com.google.protobuf:protobuf-javalite:3.19.2
    com.google.firebase:firebase-firestore:24.2.1
    └> com.google.protobuf:protobuf-javalite:3.19.2
    
    • Adding com.google.protobuf:protobuf-javalite dependency to the base module (with the same version that the dynamic feature module resolved) solves the problem so far (bundleDebug succeeds) but it sounds like a hack instead of a real solution, because it makes me need to inspect the dependency that causes the conflict and what its resolved versions are.
  • The dynamic feature module has dependency to com.google.firebase:firebase-firestore that bumps com.google.protobuf:protobuf-javalite to 3.19.2.

    • Removing com.google.firebase:firebase-firestore dependency (and all the code that needs it) from the dynamic feature module makes bundleDebug succeed.
  • Trying to backtrack, found out that it happens as soon as I move com.android.tools.build:gradle:<version> from /build.gradle to /build-conventions/build.gradle.

fikr4n
  • 3,250
  • 1
  • 25
  • 46

1 Answers1

1

Based on the last clue, it seems a bug of Android Gradle Plugin.

  • It happens in 7.3.0 and 7.3.1.
  • It doesn't happen in 7.2.0.

So the workaround is to downgrade com.android.tools.build:gradle to version 7.2.0.

fikr4n
  • 3,250
  • 1
  • 25
  • 46