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

问题描述 投票:0回答:11

当我在

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.

我的

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
11个回答
379
投票

2020年解决方案

Google 知道这个错误,因此他们制作了一个特殊的包来解决冲突。

将此添加到您的

build.gradle

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

113
投票

我在如何解决已存在的程序类型: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'

31
投票

我在构建 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'
}

20
投票

在 build.gradle 中添加这一行

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

18
投票

将其添加到您的 gradle 文件中

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

11
投票

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

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'

9
投票

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

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

7
投票

减少项目中的重复依赖项

例如,许多依赖项使用 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 外部声明为一份副本,以便所有库使用它们。


2
投票
  1. 打开

    build.gradle
    文件。

  2. 请勿更换!只需将此行添加到

    dependencies{}
    :

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

注意:要获取版本,请访问 https://mvnrepository.com/artifact/com.google.guava/guava 并查找最新版本的

jre


2
投票

将这两个实现添加到您的应用程序级别 build.gradle / app/build.gradle

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

0
投票

对我来说,没有任何效果。唯一神奇地解决了这个问题是将脱糖库更新为与我的 AGP 版本匹配

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.0'
© www.soinside.com 2019 - 2024. All rights reserved.