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


当前回答

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

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

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

其他回答

从Gradle插件用户指南:

When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases). To make the build succeed, just make sure both APKs use the same version. If the error is about an indirect dependency (a library you didn't mention in your build.gradle), just add a dependency for the newer version to the configuration

将这一行添加到构建中。gradle依赖使用更新版本的apk:

收集(“com.google.code.findbugs: jsr305:2.0.1')

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

在项目“:app”中,您可以将以下内容添加到app/build中。Gradle文件:

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

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

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

我试图使用airbnb深度链接调度,但得到了这个错误。我还必须从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'
    }

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

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

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