【问题标题】:Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar (com.google.guava:guava:20.0)在模块 guava-20.0.jar (com.google.guava:guava:20.0) 中发现重复的类 com.google.common.util.concurrent.ListenableFuture
【发布时间】:2019-10-31 12:46:46
【问题描述】:

当我在 app/build.gradle 中使用 implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0' 时,我收到此错误:

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


    【解决方案1】:

    2020 年解决方案

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

    将此添加到您的build.gradle

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

    【讨论】:

    • LOL,这应该永远留在项目中还是?我们怎么知道什么时候可以删除?
    • 令人惊叹的 Google 库
    • 这会很好用,但是,如果你没有在你的等级 defaultConfig 上启用 mutliDex,你会遇到另一个错误“Cannot fit requested classes in a single dex file (# methods: 89411 > 65536)”要解决这个问题,请确保在依赖项上添加实现 'androidx.multidex:multidex:2.0.1' 并在 android defaultConfig 上设置 multiDexEnabled true
    • 当您将快速修复推送到生产环境时
    • 问题跟踪链接?这是找出何时可以删除依赖项的唯一方法。
    【解决方案2】:

    我在How to solve Program type already present: com.google.common.util.concurrent.ListenableFuture? 找到了解决方案。 user2297550 说:

    我只是在我的应用程序 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 是 Google 的一组核心 Java 库,其中包括新的集合类型(例如 multimap 和 multiset)、不可变集合、图形库和实用程序并发、I/O、散列、缓存、原语、字符串等等!它广泛用于 Google 的大多数 Java 项目,也被许多其他公司广泛使用。”
    • 目前最新版本为implementation 'com.google.guava:guava:28.2-android'github.com/google/guava/releases
    • 还有一个更新的版本:implementation 'com.google.guava:guava:29.0-jre'
    • 版本 27.0.1 在获得“无法访问类 'com.google.common.util.concurrent.ListenableFuture'”后为我工作。无论出于何种原因,io.ktor:ktor-auth:1.5.2 出错。
    【解决方案3】:

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

    【讨论】:

    • 今天我的 Flutter 项目也突然发生了这种情况,发生在我升级了我的包和 Flutter 版本之后。
    • 严肃的人!像这样完全出乎意料的错误会破坏 Flutter 的整体开发体验。
    【解决方案4】:

    在 build.gradle 中加入这一行

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

    【讨论】:

      【解决方案5】:

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

      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'
      

      【讨论】:

        【解决方案6】:

        减少项目中的重复依赖项

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

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

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

        或者您可以管理 throw 每个依赖项以更清晰地删除包,如下所示:

        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 之外声明为一份,以便所有库使用它们。

        【讨论】:

        • 第一个示例从库中删除所有包含的模块。如果您想从导致错误的特定库中删除几个模块,请尝试特定库的第二个示例。
        【解决方案7】:

        将此添加到您的 gradle 文件中

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

        【讨论】:

        • 这对我有用。仍然使用java for android。似乎不依赖于 kotlin。
        【解决方案8】:
        1. 打开build.gradle 文件。

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

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

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

        【讨论】:

          【解决方案9】:

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

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

          【讨论】:

            【解决方案10】:

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

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

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2021-01-23
              • 2020-06-13
              • 1970-01-01
              • 2020-08-12
              • 2021-08-19
              • 2021-02-28
              • 1970-01-01
              • 2020-12-21
              相关资源
              最近更新 更多