我创建了一个新的项目在Android Studio 2.2预览1与Android应用程序和后端模块谷歌消息。这是app文件:

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的新手,无法找到这个错误是什么。我该怎么解决呢?


当前回答

反应本地

如果你在寻找react原生解决方案,那么在你受影响的node_modules gradle构建文件中写这个片段,例如,在我的例子中是firebase。

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

其他回答

在应用程序的构建中。Gradle添加以下内容:

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

强制Gradle只编译你为所有依赖项声明的版本号,不管依赖项声明的是哪个版本号。

这是由于浓缩咖啡。你可以将以下内容添加到你的应用构建中。分级来减轻这一点。

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

The accepted answer is one way of fixing the issue, because it will just apply some strategy for the problematic dependency (com.google.code.findbugs:jsr305) and it will resolve the problem around the project, using some version of this dependency. Basically it will align the versions of this library inside the whole project. There is an answer from @Santhosh (and couple of other people) who suggests to exclude the same dependency for espresso, which should work by the same way, but if the project has some other dependencies who depend on the same library (com.google.code.findbugs:jsr305), again we will have the same issue. So in order to use this approach you will need to exclude the same group from all project dependencies, who depend on com.google.code.findbugs:jsr305. I personally found that Espresso Contrib and Espresso Intents also use com.google.code.findbugs:jsr305.

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

问题,正如在你的日志中所述,是2个依赖试图使用不同版本的第三个依赖。 在app-gradle文件中添加以下内容之一:

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

删除浓缩咖啡依赖在gradle文件为我工作。

删除应用程序gradle文件中的这些行:

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