如何解决gradle build中的重复类错误?
Posted
技术标签:
【中文标题】如何解决gradle build中的重复类错误?【英文标题】:How to resolve duplicate class error in gradle build? 【发布时间】:2021-07-04 06:37:16 【问题描述】:我尝试在我的项目中使用 ibm 音调分析器 api,但如果我包含依赖项,我会收到此错误:
在模块中发现重复的类 javax.annotation.CheckForNull annotations-3.0.1.jar (com.google.code.findbugs:annotations:3.0.1) 和 jsr305-3.0.2.jar (com.google.code.findbugs:jsr305:3.0.2) 重复 在模块中找到类 javax.annotation.CheckForSigned annotations-3.0.1.jar (com.google.code.findbugs:annotations:3.0.1) 和 jsr305-3.0.2.jar (com.google.code.findbugs:jsr305:3.0.2)
我试过删除测试依赖,还是不行,请帮忙
应用文件:
apply plugin: 'com.android.application'
android
configurations.all
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
compileSdkVersion 28
defaultConfig
applicationId "com.example.loginapp"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.ibm.watson:tone-analyzer:7.0.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'jsr305:3.0.2'
)
implementation 'com.google.firebase:firebase-auth:16.2.1'
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
Gradle 构建文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
maven
url "https://dl.bintray.com/ibm-cloud-sdks/ibm-cloud-sdk-repo"
google()
jcenter()
task clean(type: Delete)
delete rootProject.buildDir
【问题讨论】:
你可以看看我的回答***.com/a/55964993/9884320然后你可以解决冲突/重复 【参考方案1】:将 applicationVariants.all 添加到您的 gradle.build:
android
applicationVariants.all variant ->
variant.getRuntimeConfiguration().exclude group: 'com.google.code.findbugs', module: 'jsr305'
【讨论】:
我有同样的错误,但 guava.jar 和 jsr305。而这个救了我。谢谢!!以上是关于如何解决gradle build中的重复类错误?的主要内容,如果未能解决你的问题,请参考以下文章
Gradle 错误:找不到任何匹配 com.android.tools.build:gradle:2.2.+ [重复]
在打包期间Gradle重复文件--JodaTime的messages.properties