首页 文章

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

提问于
浏览
218

我在 Android Studio 2.2 Preview 1 中创建了一个新项目,其中包含Android App和带有Google Messaging的Backend模块 . 这是应用程序文件:

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的新手,无法找到这个错误 . 我如何解决它?

13 回答

  • 6

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

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

    })

  • 590

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

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

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

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

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

  • 6

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

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

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

    来自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构建错误 .

  • 161

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

    1 st

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

    android {...} 中的 build.gradle 文件

    2 nd

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

    3 rd

    Build 列表中单击android studio菜单栏中的 Clean Project .
    它将重建项目,然后在第1步中重新编码.1673115_代码 .

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

  • 3

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

    compile 'com.google.code.findbugs:jsr305:2.0.1'
    
  • 2
    • 接受的答案是解决问题的一种方法,因为它只会为有问题的依赖项(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 .

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

  • 0

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

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

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

    我试图使用airbnb deeplink dispatch并得到了这个错误 . 我不得不从the . 中排除findbugs小组annotationProcessor .

    //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'
        }
    
  • 0

    那些在Android 3.0.1中获得相同错误的人可以通过简单地更新_16733120_和 targetSdkVersion to 27versions 以及 dependencies 中的实现com.android.support:appcompat-v7:27.1.1来解决它 .

  • 0

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

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

相关问题