android – Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar (com.google.guava:guava:20.0)-ThrowExceptions

Exception or error:

When I use implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0' in my app/build.gradle, I get this error:

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar (com.google.guava:guava:20.0) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)

Go to the documentation to learn how to Fix dependency resolution errors.

What I also have in my app/build.gradle is this:

implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-awareness:16.0.0'
implementation 'com.google.android.gms:play-services-cast:16.2.0'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-iid:17.1.2'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'android.arch.work:work-runtime:1.0.1'
implementation 'com.android.support:multidex:1.0.3'
apply plugin: 'com.google.gms.google-services'

Maybe one of the libraries that I am using already includes support for the In-App Messaging dependency, and then it becomes redundant? Thank you.

How to solve:

I found the solution at How to solve Program type already present: com.google.common.util.concurrent.ListenableFuture?. user2297550 said:

I merely added implementation 'com.google.guava:guava:27.0.1-android' at the end of my app gradle file and the error went away.

That was the solution for me. Now I have this and my app compiles correctly:

implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android'

###

Add this line in build.gradle

    implementation 'com.google.guava:guava:27.0.1-android'

###

Reduce duplicated dependencies from your project

For example many dependencies uses support-v4 and appcompat-v7 as included packages and then could be different versions, so you need remove this packages from inside of dependencies and create one compile dependency.

This will remove all included modules of libraries

android {
  configurations {
     all*.exclude module: 'appcompat-v7'
     all*.exclude module: 'support-v4'
  }
}

Or you can manage throw each dependency to more clear removing packages like this:

dependencies {
  implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0@aar') {//depend on your library
     transitive = true
     exclude group: 'com.android.support', module: 'appcompat-v7'
     exclude group: 'com.android.support', module: 'recyclerview-v7'
     exclude group: 'com.android.support', module: 'design'
     exclude group: 'com.android.support', module: 'support-v4'
     exclude group: 'com.squareup.retrofit2' module: 'retrofit'
     exclude group: 'com.squareup.retrofit2', module: 'retrofit'
     exclude group: 'com.google.code.gson', module: 'gson'
     exclude module: 'guava'//add this line if you have build error "found in modules guava-xxx-android.jar"
  }
}

All of removed dependencies must be declared outside of mapbox in one copy for all libraries uses them.

Leave a Reply

Your email address will not be published. Required fields are marked *