0

I have a dynamic feature module that depends on com.google.http-client:google-http-client-gson:1.40.1 which depends on com.google.guava:guava:30.1.1-android. My base module uses several Androidx libraries that transitively depend on com.google.guava:listenablefuture:1.0

When building the Relase Bundle for the project, I get the following error

R8: Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: /home/michael/MyExpenses/myExpenses/build/intermediates/module_and_runtime_deps_classes/playWithAdsInternRelease/base.jar:com/google/common/util/concurrent/ListenableFuture.class, /home/michael/MyExpenses/drive/build/intermediates/module_and_runtime_deps_classes/playRelease/feature-drive.jar:com/google/common/util/concurrent/ListenableFuture.class

I can make the build pass by providing the following in the base module build.gradle

   implementation "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"

but am not sure if this is the correct solution. My assumption is, that when the dynamic feature module is not loaded, the app will not find any implementation of the com.google.common.util.concurrent.ListenableFuture type and probably crash. Since I do not know where this type is needed, I am not sure how to test this assumption.

I could define the feature module as install-time, and not allow any unloading, but that of course beats the purpose of dynamic feature modules.

Any suggestions on how to test, how to solve?

mtotschnig
  • 1,238
  • 10
  • 30

2 Answers2

0

After giving it some thoughts, I decided to add dependency on Guava to the base module:

implementation "com.google.guava:guava:30.1.1-android"

The reason why I was hesitant to do so in the beginning was the concern of increasing the base apk size. But this does not seem to be the case with R8 removing any unused code.

mtotschnig
  • 1,238
  • 10
  • 30
0

You can use configurations in your module build.gradle to exclude multiple instances of your dependencies as like:

android {
} 

configurations {
    all {
        exclude group: 'com.google.guava', module: 'listenablefuture'
        ..
    }
}

dependencies {

}