156

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.

stkent
  • 19,772
  • 14
  • 85
  • 111
Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103

11 Answers11

371

2020 Solution

Google knows about this error so they made a special package to fix the conflict.

Add this to your build.gradle

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Ray Li
  • 7,601
  • 6
  • 25
  • 41
108

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'
Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
  • 2
    But, What it means ? We are adding some new dependency instead of removing something duplicate happned and Error gone..!!! – Jaimin Modi Feb 18 '20 at 16:06
  • @JaiminModi According to https://github.com/google/guava, "Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multiset), immutable collections, a graph library, and utilities for concurrency, I/O, hashing, caching, primitives, strings, and more! It is widely used on most Java projects within Google, and widely used by many other companies as well." – Jaime Montoya Feb 18 '20 at 16:10
  • 2
    Currently the latest version is `implementation 'com.google.guava:guava:28.2-android'` https://github.com/google/guava/releases – Joonsoo Feb 29 '20 at 00:18
  • 3
    There is an even newer release: `implementation 'com.google.guava:guava:29.0-jre'` – Roar Grønmo Jun 05 '20 at 07:26
  • Version `27.0.1` worked for me after getting "Cannot access class 'com.google.common.util.concurrent.ListenableFuture'." error with `io.ktor:ktor-auth:1.5.2` for whatever reason. – rdxdkr Mar 25 '21 at 21:11
30

I just came across this when building my Flutter project. Not quite sure why it reared its ugly head, but here I am.

So, if any Flutter devs come across this, @Ray Li's answer worked for me. The build.gradle file that you want to edit is the one in the android/app folder (ie. NOT the one in the android folder).

Just add the implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' to the dependencies section at the end of the file, as follows:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
}
Tarique Naseem
  • 1,617
  • 2
  • 15
  • 17
  • 4
    This happened to me all of a sudden today with my Flutter project too, happened after I upgraded my packages and Flutter version. – UnicornsOnLSD Oct 17 '20 at 23:00
  • Seriously man! Completely out of the blue errors like this ruin the overall Flutter dev experience. – devDeejay Jun 02 '21 at 22:59
20

Add this line in build.gradle

    implementation 'com.google.guava:guava:27.0.1-android'
Prabhu
  • 306
  • 2
  • 7
15

add this to your gradle file

configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
Dhruv garg
  • 689
  • 7
  • 22
10

I encountered the same problem. I added the line below

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

This works but I encountered another issue- Cannot fit requested classes in a single dex file (# methods: 89411 > 65536) To resolve this error make sure to enable multiDex as below

defaultConfig {
    applicationId "com.techweezy.smartsync"
    minSdkVersion 19
    targetSdkVersion 29
    versionCode 5
    versionName "1.4"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true //added this line
}

Then finally add the below lines.

   implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    implementation 'androidx.multidex:multidex:2.0.1'
Jackson
  • 315
  • 3
  • 12
8

I added this one and working perfectly for me.

implementation 'com.google.guava:guava:27.0.1-android'
Faisal Ahmed
  • 816
  • 9
  • 12
7

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.

vishwajit76
  • 2,300
  • 20
  • 16
  • First example remove all included module from libraries. If you want to remove few modules from perticular library which is responsible for error then try second example for perticular library. – vishwajit76 Mar 13 '20 at 06:09
2
  1. Open build.gradle file.

  2. Do Not replace! Just add this line into dependencies{}:

    implementation 'com.google.guava:guava:<version>-jre'
    

Note: To get the version go to https://mvnrepository.com/artifact/com.google.guava/guava and find for the latest version of jre.

Pasindu Jayanath
  • 892
  • 10
  • 27
2

add these two implementations to your app level build.gradle / app/build.gradle

implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android'
Rashid Iqbal
  • 1,123
  • 13
  • 13
0

For me, nothing worked. The only thing that fixed it magically was to update the desugaring library to the matching for my AGP version:

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.0'
Arnyminer Z
  • 5,784
  • 5
  • 18
  • 32