在模块guava-20.0.jar(com.google.guava:guava:20.0)中找到的重复类com.google.common.util.concurrent.ListenableFuture

Jai*_*oya 3 android guava firebase firebase-in-app-messaging

在我的中使用implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'app/build.gradle,出现以下错误:

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.
Run Code Online (Sandbox Code Playgroud)

我的内在app/build.gradle是:

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'
Run Code Online (Sandbox Code Playgroud)

也许我正在使用的库之一已经包含对In-App Messaging依赖的支持,然后它变得多余了?谢谢。

Ray*_* Li 280

2020解决方案

谷歌知道这个错误,所以他们制作了一个特殊的包来解决这个冲突。

将此添加到您的 build.gradle

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Run Code Online (Sandbox Code Playgroud)

  • 哈哈,这应该永远留在项目中吗?我们如何知道什么时候可以将其删除? (28认同)
  • 哇,来自 Google 的令人印象深刻的图书馆 (18认同)
  • 这会很好地工作,但是,如果您没有在您的年级defaultConfig上启用mutliDex,您将遇到另一个错误“无法在单个dex文件中容纳请求的类(#方法:89411> 65536)”要解决此问题,请确保添加实现'androidx.multidex:multidex:2.0.1' 在你的依赖项上并在 android defaultConfig 上设置 multiDexEnabled true (7认同)
  • 2022 年 4 月:使用实现“com.google.guava:guava:31.1-jre”解决了该问题 (4认同)
  • 当您对生产进行快速修复时 (3认同)
  • 问题跟踪器链接?这是确定何时可以删除依赖关系的唯一方法。 (2认同)

Tar*_*eem 19

我刚刚在构建 Flutter 项目时遇到了这个问题。不太确定为什么它抬起丑陋的头,但我在这里。

因此,如果任何 Flutter 开发人员遇到此问题,@Ray Li 的回答对我有用。将build.gradle要编辑的文件是一个在android/app文件夹中(不是一个即中android的文件夹)。

只需implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'在文件末尾的依赖项部分添加,如下所示:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
}
Run Code Online (Sandbox Code Playgroud)

  • 今天我的 Flutter 项目也突然发生了这种情况,是在我升级软件包和 Flutter 版本之后发生的。 (3认同)

Dhr*_*arg 18

将其添加到您的 gradle 文件中

configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
Run Code Online (Sandbox Code Playgroud)


小智 12

在 build.gradle 添加这一行

    implementation 'com.google.guava:guava:27.0.1-android'
Run Code Online (Sandbox Code Playgroud)


Fai*_*med 9

我添加了这个并且非常适合我。

implementation 'com.google.guava:guava:27.0.1-android'
Run Code Online (Sandbox Code Playgroud)


Jac*_*son 8

我遇到了同样的问题。我在下面添加了一行

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Run Code Online (Sandbox Code Playgroud)

这有效,但我遇到了另一个问题 -Cannot fit requested classes in a single dex file (# methods: 89411 > 65536)要解决此错误,请确保按如下方式启用 multiDex

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
}
Run Code Online (Sandbox Code Playgroud)

然后最后添加以下几行。

   implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    implementation 'androidx.multidex:multidex:2.0.1'
Run Code Online (Sandbox Code Playgroud)


Jai*_*oya 7

我在“ 如何解决程序类型”中找到了解决方案:com.google.common.util.concurrent.ListenableFuture?。user2297550说:

我只是implementation 'com.google.guava:guava:27.0.1-android'在我的应用gradle文件的末尾添加了内容,错误消失了。

那是我的解决方案。现在我有了这个,我的应用程序可以正确编译:

implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android'
Run Code Online (Sandbox Code Playgroud)

  • 但是,这意味着什么?我们正在添加一些新的依赖项,而不是删除重复发生的内容和错误消失..!!! (2认同)
  • 目前最新版本是 `implementation 'com.google.guava:guava:28.2-android'` https://github.com/google/guava/releases (2认同)
  • 还有一个更新的版本:`implementation 'com.google.guava:guava:29.0-jre'` (2认同)

vis*_*hwa 5

减少项目中的重复依赖项

例如,许多依赖项使用 support-v4 和 appcompat-v7 作为包含的包,然后可能是不同的版本,因此您需要从依赖项内部删除这些包并创建一个编译依赖项。

这将删除所有包含的库模块

android {
  configurations {
     all*.exclude module: 'appcompat-v7'
     all*.exclude module: 'support-v4'
  }
}
Run Code Online (Sandbox Code Playgroud)

或者您可以管理抛出每个依赖项以更清楚地删除这样的包:

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"
  }
}
Run Code Online (Sandbox Code Playgroud)

所有删除的依赖项都必须在 mapbox 之外声明为一份副本,以便所有库使用它们。