8

这是我build.gradle有冲突的一部分:

...
dependencies {
  classpath 'com.android.tools.build:gradle:1.1.1'
}
...
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' )
...

我在日志中看到的问题:

WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (21.0.3) and test app (20.0.0) differ.

显然,它从类路径中删除了冲突的依赖项。我不确定它是插件gradle还是android gradle插件。

我尝试了下一个:

  testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
    exclude group: 'com.android.support', module: 'support-annotations'
  }

但是我仍然有编译错误,所以排除了依赖。

我尝试了下一个:

configurations.all {
  resolutionStrategy {
    // fail eagerly on version conflict (includes transitive dependencies)
    // e.g. multiple different versions of the same dependency (group and name are equal)
    failOnVersionConflict()

    // force certain versions of dependencies (including transitive)
    //  *append new forced modules:
    force 'com.android.support:support-annotations:21.0.3'
    //  *replace existing forced modules with new ones:
    forcedModules = ['com.android.support:support-annotations:21.0.3']
  }
}

但看起来它不起作用,因为它在第一次冲突时没有失败,而且我仍然有编译错误。

你会有什么建议?

更新删除依赖项是什么意思-我看到很多assertj未找到的编译错误

4

3 回答 3

7

我遇到了同样的问题。这为我修复了它:

testCompile('com.squareup.assertj:assertj-android:1.0.0'){
    exclude group: 'com.android.support', module:'support-annotations'
}
于 2015-02-27T21:48:21.550 回答
1

接受的答案对我不起作用。但是,添加以下内容确实对我有用:

androidTestCompile 'com.android.support:support-annotations:23.0.1'

和:

testCompile 'com.android.support:support-annotations:23.0.1'

基于https://stackoverflow.com/a/29947562/2832027

于 2015-09-03T22:37:14.653 回答
-2

你需要改变:

testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
    exclude group: 'com.android.support', module: 'support-annotations'
}

至:

compile('com.squareup.assertj:assertj-android:1.0.0') {
    exclude group: 'com.android.support', module: 'support-annotations'
}

还要确保您的测试文件夹被调用test而不是androidTest

于 2015-04-27T13:04:26.330 回答