添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

在模块guava-20.0.jar(com.google.guava:guava:20.0)中发现重复的类com.google.com.util.concurrent.ListenableFuture。

140 人关注

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.

我的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'

也许我使用的某个库已经包括了对应用内消息的支持,那么它就变得多余了?谢谢你。

android
firebase
guava
firebase-in-app-messaging
Jaime Montoya
Jaime Montoya
发布于 2019-06-18
11 个回答
Ray Li
Ray Li
发布于 2022-11-25
已采纳
0 人赞同

2020 Solution

谷歌知道这个错误,所以他们做了一个特殊的包来修复这个冲突。

添加到您的 build.gradle

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    
傻子,这应该是永远留在项目中还是?我们怎么知道它什么时候可以被删除?
哇,谷歌的图书馆令人印象深刻
This will work well, however, if you have not enabled mutliDex on your grade defaultConfig you will run into another error " Cannot fit requested classes in a single dex file (# methods: 89411 > 65536) " To solve this make sure you add implementation 'androidx.multidex:multidex:2.0.1' on your dependencies and set multiDexEnabled true on android defaultConfig
当你把一个快速修复的方法推到生产中时
我可以确认,即使是在2022年,这也是一种工作。
Jaime Montoya
Jaime Montoya
发布于 2022-11-25
0 人赞同

我在以下网站找到了解决方案 如何解决已经存在的程序类型:com.google.common.util.concurrent.ListenableFuture? .用户2297550说。

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

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

implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
implementation 'com.google.guava:guava:27.0.1-android'
    
但是,这意味着什么?我们正在添加一些新的依赖关系,而不是删除一些重复发生和错误的东西...!!
@JaiminModi 根据 github.com/google/guava , "Guava是谷歌的一套核心Java库,包括新的集合类型(如multimap和multiset),不可变的集合,一个图库,以及用于并发、I/O、散列、缓存、基元、字符串等的实用程序。它被广泛用于谷歌内部的大多数Java项目,同时也被许多其他公司广泛使用"。
目前最新版本是 implementation 'com.google.guava:guava:28.2-android' github.com/google/guava/releases
还有一个更新的版本。替换代码0
版本 27.0.1 在得到 "Cannot access class 'com.google.common.util.concurrent.ListenableFuture'. "的错误后为我工作, io.ktor:ktor-auth:1.5.2 由于某种原因。
Tarique Naseem
Tarique Naseem
发布于 2022-11-25
0 人赞同

我刚刚在构建我的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'
    
UnicornsOnLSD
今天我的Flutter项目也突然发生了这种情况,是在我升级了我的软件包和Flutter版本之后发生的。
认真的人!像这样完全突如其来的错误破坏了整个Flutter的开发经验。
Prabhu
Prabhu
发布于 2022-11-25
0 人赞同

在build.gradle中添加这一行

    implementation 'com.google.guava:guava:27.0.1-android'
    
Jackson
Jackson
发布于 2022-11-25
0 人赞同

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

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

这很有效,但我遇到了另一个问题- 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

然后最后添加以下几行。

   implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    implementation 'androidx.multidex:multidex:2.0.1'
    
Dhruv garg
Dhruv garg
发布于 2022-11-25
0 人赞同

把这个添加到你的gradle文件中

configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
    
这对我来说是有效的。仍然使用安卓的java。似乎不依赖于kotlin。
vishwajit76
vishwajit76
发布于 2022-11-25
0 人赞同

减少你的项目中重复的依赖性

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

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

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

或者你可以像这样管理抛出每个依赖关系,以更清楚地删除软件包。

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"

所有被删除的依赖必须在mapbox之外的一个副本中声明,以便所有库使用它们。

第一个例子是从库中删除所有的模块。如果你想从某个特定的库中删除一些导致错误的模块,那么请尝试第二个例子,针对特定的库。
Faisal Ahmed
Faisal Ahmed
发布于 2022-11-25
0 人赞同

我添加了这个,对我来说工作很完美。

implementation 'com.google.guava:guava:27.0.1-android'
    
Pasindu Jayanath
Pasindu Jayanath
发布于 2022-11-25
0 人赞同
  • Open build.gradle file.

  • 不要替换!只要把这一行加入到 dependencies{} 中。

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

    Note: To get the version go to https://mvnrepository.com/artifact/com.google.guava/guava并找到最新版本的jre

  • Rashid Iqbal
    Rashid Iqbal
    发布于 2022-11-25
    0 人赞同

    将这两个实现添加到你的应用层 build.gradle / app/build.gradle 中。

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