ChatGPT解决这个技术问题 Extra ChatGPT

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

我在 Android Studio 2.2 Preview 1 中创建了一个新项目,其中包含 Android 应用程序和带有 Google 消息传递的后端模块。这是应用程序文件:

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”冲突。应用程序 (1.3.9) 和测试应用程序 (2.0.1) 的已解决版本不同。有关详细信息,请参阅 http://g.co/androidstudio/app-test-app-conflict。

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


g
gbhall

在您应用的 build.gradle 中添加以下内容:

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

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


解释这个片段可能很有用。
@Andy它明确告诉Gradle应该编译哪个版本(无论依赖项状态是哪个版本号)......同时强制执行 v 2.0.1 也有效(无论如何,两个版本都需要强制相同)。
@MartinZeitler,但它并没有真正解释这个问题来自哪里。我今天遇到了这个问题 testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
万分感谢。这在 3 年半之后仍然很有帮助。 ;)
@Kartik haha jeeze,那是很久以前的事了!不客气,谢谢,希望对你有帮助!我早就停止了Android开发,但我相信有一天我会再次拿起它😊
S
Santhosh

这是由于浓缩咖啡。您可以将以下内容添加到您的应用程序 build.grade 以缓解这种情况。

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

不工作。设置为答案的问题有效。
@Warpzit - 这对我有用(就像接受的答案一样)。
@TedHopp 我实际上最终做了其他事情。我对 youtube api 的 gradle compile 有问题,所以我最终改用了 lib jar。
这很可能是每个人都在寻找的答案。在大多数情况下,Android Studio 默认在依赖项列表中包含 Espresso,您需要排除一些东西才能与其他库一起使用它。除了@Santhosh 所说的,我还exclude group: 'com.android.support', module: 'support-annotations'
好吧,我刚刚删除了 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') { exclude group: 'com.google.code.findbugs' } 并且它起作用了:D因为主要是问题您的解决方法是有些人已经拥有 * androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })* 在他们的 gradle 文件中这样的东西,并且添加另一个排除会引发异常,所有的冰雹 gradle 脚本,仍然是你的支持:)
L
Liwen Zhao

方法 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'
    ...
}

有版本更新:androidTestCompile 'com.google.code.findbugs:jsr305:3.0.1'
C
Community

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 构建错误。


E
ElliotCui

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

第一

添加

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

到您在 android {...} 中的 build.gradle 文件

第二

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

第三

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

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


W
Wahib Ul Haq

当我添加 module: 'jsr305' 作为附加的排除语句时,对我来说一切都很好。

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

})


n
nbtk

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

androidTestCompile 'com.google.code.findbugs:jsr305:2.0.1'
androidTestCompile 'com.google.code.findbugs:jsr305:1.3.9'

S
Stoycho Andreev

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

我希望这个想法能帮助人们了解这里到底发生了什么以及事情是如何工作的(不仅仅是复制粘贴一些代码):)。


A
Ayman Al-Absi

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

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

K
Kai Wang

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

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

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

如果您只是删除 espresso 依赖项,您将无法再测试您的应用程序,因此此解决方案显然无法正常工作。
j
j2emanue

我试图使用 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'
    }

A
Arjun

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


D
Diya Bhat

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

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

I
Indivision Dev

对于 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}

这是我第一次看到 { force = true } 标志。我试过了,它立即对我有用。我需要为我的项目将 androidx.appcompat 保留为 v1.0.2,因为我添加的库将该依赖项设置为 v1.1.0。
F
Faisal Hassan

反应原生

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

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

关注公众号,不定期副业成功案例分享
关注公众号

不定期副业成功案例分享

领先一步获取最新的外包任务吗?

立即订阅