在Gradle构建中出现重复的类,在Android Studio应用程序中。

huangapple go评论78阅读模式
英文:

Duplicate classes in Gradle build, in Android Studio Application

问题

我已经为这个问题纠结了几个小时,当我添加这个特定的依赖时,我目前遇到了一个重复类的错误。

implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

我的 App  Build.gradle 文件如下:

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

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"
    defaultConfig {
        applicationId "com.example.digitaldocs"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0-beta01'
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:24.0.3'

    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.3'
    //noinspection GradleCompatible
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.firebase:firebase-auth:19.4.0'
    implementation 'com.google.firebase:firebase-firestore:21.6.0'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation "androidx.core:core-ktx:+"
    implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'androidx.annotation:annotation:1.1.0'
}
repositories {
    mavenCentral()
}

我的项目级 Build.gradle 文件如下:

// 顶层 Build 文件,在这里您可以添加所有子项目/模块都通用的配置选项。

buildscript {
    ext.kotlin_version = '1.4.10'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 注意:不要在此处放置应用程序的依赖项;它们应属于各个模块的 build.gradle 文件中
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

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

我的堆栈跟踪如下:

Duplicate class com.google.common.annotations.Beta found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtCompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtIncompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.VisibleForTesting found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Absent found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$1 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$State found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Ascii found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android)  jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$1 found in modules jetified-guava

<details>
<summary>英文:</summary>

I have been stumped on this problem for hours, I am currently getting a duplicate classes error, when adding this specific dependency.

        implementation &#39;com.google.apis:google-api-services-vision:v1-rev369-1.23.0&#39;

My App Level Build.gradle file is

  

      apply plugin: &#39;com.android.application&#39;
    apply plugin: &#39;kotlin-android&#39;
    apply plugin: &#39;com.google.gms.google-services&#39;
    
    
    android {
        compileSdkVersion 30
        buildToolsVersion &quot;30.0.2&quot;
        defaultConfig {
            applicationId &quot;com.example.digitaldocs&quot;
            minSdkVersion 16
            targetSdkVersion 30
            versionCode 1
            versionName &quot;1.0&quot;
            multiDexEnabled true
            vectorDrawables.useSupportLibrary = true
    
    
            testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
            }
        }
    }
    
    
    dependencies {
        implementation fileTree(dir: &#39;libs&#39;, include: [&#39;*.jar&#39;])
        implementation &#39;androidx.appcompat:appcompat:1.0.0-beta01&#39;
        implementation &#39;com.google.android.material:material:1.0.0-beta01&#39;
        implementation &#39;androidx.constraintlayout:constraintlayout:1.1.2&#39;
        implementation &#39;androidx.vectordrawable:vectordrawable:1.0.0-beta01&#39;
        implementation &#39;com.google.firebase:firebase-database:19.3.0&#39;
        implementation &#39;androidx.legacy:legacy-support-v4:1.0.0&#39;
        implementation &#39;com.android.support:support-annotations:28.0.0&#39;
        implementation &#39;com.google.firebase:firebase-ml-vision:24.0.3&#39;
    
        testImplementation &#39;junit:junit:4.12&#39;
        implementation &#39;com.android.support:multidex:1.0.3&#39;
        //noinspection GradleCompatible
        implementation &#39;com.android.support:support-v4:26.1.0&#39;
        implementation &#39;com.google.firebase:firebase-auth:19.4.0&#39;
        implementation &#39;com.google.firebase:firebase-firestore:21.6.0&#39;
        androidTestImplementation &#39;androidx.test:runner:1.1.0-alpha4&#39;
        androidTestImplementation &#39;androidx.test.espresso:espresso-core:3.1.0-alpha4&#39;
        implementation &quot;androidx.core:core-ktx:+&quot;
        implementation &#39;com.google.apis:google-api-services-vision:v1-rev369-1.23.0&#39;
    
        implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
    
        implementation &#39;androidx.annotation:annotation:1.1.0&#39;
    }
    repositories {
        mavenCentral()
    }


my project level build.gradle file is 

        // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        ext.kotlin_version = &#39;1.4.10&#39;
        repositories {
            google()
            jcenter()
            
        }
        dependencies {
            classpath &#39;com.android.tools.build:gradle:4.0.1&#39;
            classpath &#39;com.google.gms:google-services:4.3.3&#39;
            classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

**My Stack Trace is as follows**

        Duplicate class com.google.common.annotations.Beta found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.annotations.GwtCompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.annotations.GwtIncompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.annotations.VisibleForTesting found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.Absent found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.AbstractIterator found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.AbstractIterator$1 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.AbstractIterator$State found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.Ascii found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat$1 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat$2 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat$3 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat$4 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
    Duplicate class com.google.common.base.CaseFormat$5 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)



</details>


# 答案1
**得分**: 2

```plaintext
将以下内容替换为:

    implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

用以下内容替换:

    implementation ('com.google.apis:google-api-services-vision:v1-rev369-1.23.0'){
        exclude group:'com.google.guava'
    }
英文:

Replace this

implementation &#39;com.google.apis:google-api-services-vision:v1-rev369-1.23.0&#39;

With this

implementation (&#39;com.google.apis:google-api-services-vision:v1-rev369-1.23.0&#39;){
exclude group:&#39;com.google.guava&#39;
}

huangapple
  • 本文由 发表于 2020年10月3日 10:38:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/64180196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定