【问题标题】:Duplicate class found in modules guava-26.0-android.jar and guava-jdk5-17.0.jar在模块 guava-26.0-android.jar 和 guava-jdk5-17.0.jar 中发现重复的类
【发布时间】:2020-08-12 06:56:11
【问题描述】:

转到文档了解如何修复依赖解析错误。

在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava-jdk5: 17.0)

我最初制作了这个项目,它使用了 Google 的 Cloud Vision API,一切正常。 但现在我无法解决集成 Firestore 所需的这种依赖关系。

implementation 'com.google.firebase:firebase-firestore:21.4.3'

我试过了

implementation 'com.google.firebase:firebase-firestore:21.4.3' exclude module: 'com.google.gauva:gauva-jdk5:17.0'

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

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

android.useAndroidX=true//causes lot of errors, tried refactoring, but core error remained
android.enableJetifier=true//no effect

正如 StackOverflow、GitHub 等上的大多数其他帖子中所建议的那样。我也尝试多次清理和构建。 但到目前为止似乎没有任何效果。包括 Firestore 实施是经过验证的原因。 应用程序 build.gradle 是

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"

defaultConfig {
    applicationId "com.google.sample.cloudvision"
    minSdkVersion 24
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    buildTypes.each {
        it.buildConfigField 'String', 'API_KEY', "\"AIzaSyCuSEBxcK9n6_ojdCo6uUDFALdZL2w024Y\""
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
    implementation.exclude module:'gauva-jdk5'
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
}

dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-firestore:21.4.3' exclude module: 'com.google.gauva:gauva-jdk5:17.0'
testImplementation 'junit:junit:4.12'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.0.2'
//noinspection GradleCompatible
implementation 'com.android.support:design:27.0.2'
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0' exclude module: 'com.google.gauva:gauva-jdk5:17.0'
//    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
//    implementation 'com.google.guava:guava:26.0-android'
}

项目build.gradle是

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.6.3'
    classpath 'com.google.gms:google-services:4.3.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

初始错误日志如下

在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar ( com.android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com .android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar 中发现重复的类 android.support.v4.app.INotificationSideChannel$Stub$Proxy (com.android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com.android) 中发现重复的类 android.support.v4.os.IResultReceiver .support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com .android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar 中发现重复的类 android.support.v4.os.IResultReceiver$Stub$Proxy (com.android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com.android) 中发现重复的类 android.support.v4.os.ResultReceiver .support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com. android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com .android.support:support-compat:27.0.2) 在模块 core-1.0.0-runtime.jar (androidx.core:core:1.0.0) 和 support-compat-27.0.2-runtime.jar (com .android.support:support-compat:27.0.2) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.annotations.Beta -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.annotations.GwtCompatible -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.annotations.GwtIncompatible -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.annotations.VisibleForTesting -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.base.Absent -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:guava) 中发现重复的类 com.google.common.base.AbstractIterator -jdk5:17.0) 在模块 guava-26.0-android.jar (com.google.guava:guava:26.0-android) 和 guava-jdk5-17.0.jar (com.google.guava:番石榴-jdk5:17.0) ......相同的错误重复了大约 2300000 个单词...................... …………

gradle 属性 -> 5.6.4

【问题讨论】:

    标签: android firebase android-studio gradle google-cloud-firestore


    【解决方案1】:

    可能为时已晚。但是,我正在为您的问题写一个答案。

    我有同样的问题。我使用的是 Youtube Data API v3。经过几次搜索并看到 Stackoverflow 的答案后,我将它们混合在一起,不知何故它起作用了!!

    这就是我所做的一切,它奏效了。

    1. 在应用级 build.gradle 文件中添加了 配置。如下所示

      configurations {
      implementation.exclude module:'gauva-jdk5'
      all*.exclude group: 'com.google.guava', module: 'listenablefuture' }
      
    2. 在依赖块中添加这两行

      实现 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' 实现 'com.google.guava:guava:26.0-android'

      1. 在我所依赖的 youtbe 数据 api 所需的依赖项中

      排除组:'com.google.guava'

    如下图

    implementation ('com.google.api-client:google-api-client-android:1.22.0') {
            exclude group: 'org.apache.httpcomponents'
            exclude group:'com.google.guava'
        }
        implementation ('com.google.apis:google-api-services-youtube:v3-rev183-1.22.0') {
            exclude group: 'org.apache.httpcomponents'
            exclude group:'com.google.guava'
        }
    

    如果您愿意,可以在 GitHub gist 上查看我的整个 build.gradle 文件 here

    谢谢你:-)

    【讨论】:

    • 在我的情况下,我必须将“-jdk5”添加到排除组,即排除组:'com.google.guava-jdk5'
    猜你喜欢
    • 2021-01-23
    • 2020-06-13
    • 2020-12-21
    • 1970-01-01
    • 2019-10-31
    • 2018-04-17
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多