错误:与依赖项“com.google.code.findbugs:jsr305”冲突

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误:与依赖项“com.google.code.findbugs:jsr305”冲突相关的知识,希望对你有一定的参考价值。

我在android Studio 2.2 Preview 1中使用Android App和Backend模块在Google Messaging中创建了一个新项目。这是应用程序文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.xxx.xxx"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support:support-annotations:23.4.0'
    compile project(path: ':backend', configuration: 'android-endpoints')
}

但它给了:

错误:与依赖项'com.google.code.findbugs:jsr305'冲突。 app(1.3.9)和测试app(2.0.1)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict

我是Android的新手,无法找到这个错误。我如何解决它?

答案

在你的应用程序的build.gradle中添加以下内容:

android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

强制Gradle只编译您为所有依赖项声明的版本号,无论依赖项声明了哪个版本号。

另一答案

删除gradle文件中的espresso依赖项对我有用。

删除app gradle文件中的那些行:

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
另一答案

在项目':app'中,您可以将以下内容添加到app / build.gradle文件中:

android {
 configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
 }
 }
另一答案

我试图使用airbnb deeplink dispatch并得到了这个错误。我还必须从annotationProcessor中排除findbugs组。

//airBnb
    compile ('com.airbnb:deeplinkdispatch:3.1.1'){
        exclude group:'com.google.code.findbugs'
    }
    annotationProcessor ('com.airbnb:deeplinkdispatch-processor:3.1.1'){
        exclude group:'com.google.code.findbugs'
    }
另一答案

那些在Android 3.0.1中得到相同错误的人可以通过简单地将compileSdkVersion和targetSdkVersion的版本更新为27并在依赖项中实现com.android.support:appcompat-v7:27.1.1'来解决它。

另一答案

REACT NATIVE

如果您正在寻找本机解决方案,请在受影响的node_modules gradle构建文件中编写此代码段,例如:在我的情况下firebase。

android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
    }
}
另一答案

对于react-native-firebase,将其添加到app/build.gradle依赖项部分使它对我有用:

implementation('com.squareup.okhttp3:okhttp:3.12.1') { force = true }
implementation('com.squareup.okio:okio:1.15.0') { force = true }
implementation('com.google.code.findbugs:jsr305:3.0.2') { force = true}
另一答案

这是因为意式浓缩咖啡。您可以将以下内容添加到您的应用build.grade以缓解此问题。

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
  exclude group: 'com.google.code.findbugs'
}
另一答案

方法1:我删除了espresso-core系列上的androidTestCompile,它自动包含在一个新项目中。然后我的Android Studio编译干净。

androidTestCompile位于“build.gradle(Module:app)”中:

dependencies {
    ...
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    ...
}

我不知道这个删除是否会有任何问题,但它肯定适用于我现在的项目。

方法2:在findbugs上添加排除也有效:

dependencies {
    ...
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs'
    })
    ...
}

方法3:强制使用特定版本进行编译: (在下面我强制它用更高版本编译。)

dependencies {
    ...
    androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
    ...
}
另一答案

来自Gradle Plugin User Guide

运行检测测试时,主APK和测试APK共享相同的类路径。如果主APK和测试APK使用相同的库(例如Guava)但是在不同的版本中,Gradle构建将失败。如果gradle没有捕获到,那么您的应用程序在测试期间和正常运行期间可能会有不同的行为(包括其中一个案例中的崩溃)。

要使构建成功,只需确保两个APK使用相同的版本。如果错误是关于间接依赖项(您在build.gradle中未提及的库),则只需将新版本的依赖项添加到配置中

将此行添加到build.gradle依赖项中,以便为两个APK使用更新版本:

compile('com.google.code.findbugs:jsr305:2.0.1')

为了将来参考,您可以检查您的Gradle控制台,它将在错误旁边提供一个有用的链接,以帮助解决任何gradle构建错误。

另一答案

当我添加module: 'jsr305'作为额外的排除声明时,这对我来说都很好。

 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'jsr305'

})

另一答案

这种情况发生的原因是diff依赖使用diff版本的相同lib。 因此,有3个步骤或(1个步骤)来解决这个问题。

1st

configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}

到你在build.gradleandroid {...}文件

2nd

在android studio中打开终端 运行./gradlew -q app:dependencies命令。

3rd

点击Clean Project列表中android studio菜单栏中的Build。 它将重建项目,然后在第1步中使用remove代码。

也许你只需要执行第二步。发生错误时我无法回滚。试试。

另一答案

正如您的日志中所述,问题是2个依赖项试图使用不同版本的第3个依赖项。将以下其中一项添加到app-gradle文件中:

androidTestCompile 'com.google.code.findbugs:jsr305:2.0.1'
androidTestCompile 'com.google.code.findbugs:jsr305:1.3.9'
另一答案

将此添加到依赖项以强制使用最新版本的findbugs库:

compile 'com.google.code.findbugs:jsr305:2.0.1'
另一答案
  1. 接受的答案是解决问题的一种方法,因为它只会为有问题的依赖项(com.google.code.findbugs:jsr305)应用一些策略,它将使用此依赖项的某个版本来解决项目周围的问题。基本上它会在整个项目中对齐这个库的版本。
  2. @Santhosh(以及其他几个人)的答案建议排除espresso的相同依赖关系,这应该以相同的方式工作,但是如果项目有一些其他依赖关系依赖于同一个库(com.google .code.findbugs:jsr305),我们再次遇到同样的问题。因此,为了使用此方法,您需要从依赖于com.google.code.findbugs:jsr305的所有项目依赖项中排除相同的组。我个人发现Espresso Contrib和Espresso Intents也使用com.google.code.findbugs:jsr305。

我希望这个想法可以帮助有人意识到这里到底发生了什么,以及如何工作(不只是复制粘贴一些代码):)。

以上是关于错误:与依赖项“com.google.code.findbugs:jsr305”冲突的主要内容,如果未能解决你的问题,请参考以下文章

与依赖项“com.android.support:support-v4”冲突

pom.xml 每次添加新依赖时都会出错

如何在不作为模块使用的情况下更新第三方库中的依赖项?

安装 scala 测试库依赖项错误

Google Play 服务 - 找不到依赖项

错误无法解决依赖项 grails