英文:
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 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'
My App Level Build.gradle file is
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()
}
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 = '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"
// 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 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'
With this
implementation ('com.google.apis:google-api-services-vision:v1-rev369-1.23.0'){
exclude group:'com.google.guava'
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论