【问题标题】:Android AssertJ 1.0.0 with Android gradle 1.1.1Android AssertJ 1.0.0 与 Android gradle 1.1.1
【发布时间】:2015-09-04 06:37:14
【问题描述】:

这是我的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 not found

【问题讨论】:

    标签: android gradle android-gradle-plugin assertj android-assertj


    【解决方案1】:

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

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

    【讨论】:

    • 对我不起作用。我还是看到了很多error: package org.assertj.android.api does not exist import static org.assertj.android.api.Assertions.assertThat;
    【解决方案2】:

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

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

    和:

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

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

    【讨论】:

    • 问题和答案对我来说已经过时了。我现在在项目中使用 assertj 没有任何问题。同样,AssetJ for Android 已经升级了两个版本
    • 当前版本的 AssertJ (1.1.0) 不使用最新版本的 support-annotations (23.0.1),问题仍然存在。最新版本的 Espresso 和 com.android.support.test:rules 也使用旧版本的支持注释。我在搜索错误时发现了您的问题。
    【解决方案3】:

    你需要改变:

    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

    【讨论】:

    • 但是编译用于发布版本而不是测试版本所以发布代码会有assertj的东西?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 2020-03-17
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多