【问题标题】:AndroidTests stopped building after adding androidx.fragment:fragment-testing dependency添加 androidx.fragment:fragment-testing 依赖项后,AndroidTests 停止构建
【发布时间】:2019-10-15 08:20:16
【问题描述】:

在我将fragment-testing 依赖项添加到我的项目之后:

    // Testing dependencies
    espressoVersion = '3.2.0-beta01'
    testCoreVersion = '1.1.0'
    runnerVersion = '1.1.0'
    extJunitVersion = '1.1.0'
    testRulesVersion = '1.1.0'
    fragmentVersion = '1.1.0-alpha09'
    orchestratorVersion = '1.1.0'
    uiAutomatorVersion = '2.2.0'
    junitVersion = '4.12'
    mockitoVersion = '2.7.22'
    robolectricVersion = '4.2.1'
    liveDataTestingVersion = '1.1.0'
    androidArchCoreTestingVersion = '2.0.0'

androidTestImplementation("androidx.test.espresso:espresso-core:$rootProject.ext.espressoVersion")
androidTestImplementation "androidx.test:core:$rootProject.ext.testCoreVersion"
androidTestImplementation("androidx.test:runner:$rootProject.ext.runnerVersion")
androidTestImplementation "androidx.test.ext:junit:$rootProject.ext.extJunitVersion"
androidTestUtil ("androidx.test:orchestrator:$rootProject.ext.orchestratorVersion")
androidTestImplementation("androidx.test.espresso:espresso-intents:$rootProject.ext.espressoVersion")
implementation "androidx.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"
androidTestImplementation "androidx.test.uiautomator:uiautomator:$rootProject.ext.uiAutomatorVersion"
testImplementation "junit:junit:$rootProject.ext.junitVersion"
androidTestImplementation("androidx.test:rules:$rootProject.ext.testRulesVersion")
// required if you want to use Mockito for unit tests
testImplementation "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
// required if you want to use Mockito for Android tests
androidTestImplementation "org.mockito:mockito-android:$rootProject.ext.mockitoVersion"
testImplementation "org.robolectric:robolectric:$rootProject.ext.robolectricVersion"
testImplementation "org.robolectric:shadows-multidex:$rootProject.ext.robolectricVersion"
// LiveData Testing utility
testImplementation "com.jraska.livedata:testing:$rootProject.ext.liveDataTestingVersion"
testImplementation "androidx.arch.core:core-testing:$rootProject.ext.androidArchCoreTestingVersion"
// Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
implementation ("androidx.fragment:fragment-testing:$rootProject.ext.fragmentVersion")

当我尝试构建 androidTests 时失败:

FAILURE:构建失败并出现异常。

出了什么问题: 无法确定任务 ':MyApp:mergeEsmartliveDebugAndroidTestResources' 的依赖关系。

无法解析配置“:MyApp:esmartliveDebugAndroidTestRuntimeClasspath”的所有任务依赖项。 无法解析 androidx.test:core:1.1.0。 要求: 项目:MyApp 项目:MyApp > androidx.test.ext:junit:1.1.0 项目:MyApp > androidx.fragment:fragment-testing:1.1.0-alpha09 找不到满足版本约束的“androidx.test:core”版本: 依赖路径 'MyApp:unspecified' --> 'androidx.test:core:1.1.0' 约束路径 'MyApp:unspecified' --> 'androidx.test:core:{strictly 1.1.0}' 因为以下原因:esmartliveDebugRuntimeClasspath 使用版本 1.1.0 依赖路径 'MyApp:unspecified' --> 'androidx.test.ext:junit:1.1.0' --> 'androidx.test:core:1.1.0' 依赖路径 'MyApp:unspecified' --> 'androidx.test.espresso:espresso-intents:3.2.0-beta01' --> 'androidx.test:core:1.2.0-beta01' 依赖路径 'MyApp:unspecified' --> 'androidx.fragment:fragment-testing:1.1.0-alpha09' --> 'androidx.test:core:1.1.0'

无法解析 androidx.test:core:{strictly 1.1.0}。 要求: 项目:MyApp 找不到满足版本约束的“androidx.test:core”版本: 依赖路径 'MyApp:unspecified' --> 'androidx.test:core:1.1.0' 约束路径 'MyApp:unspecified' --> 'androidx.test:core:{strictly 1.1.0}' 因为以下原因:esmartliveDebugRuntimeClasspath 使用版本 1.1.0 依赖路径 'MyApp:unspecified' --> 'androidx.test.ext:junit:1.1.0' --> 'androidx.test:core:1.1.0' 依赖路径 'MyApp:unspecified' --> 'androidx.test.espresso:espresso-intents:3.2.0-beta01' --> 'androidx.test:core:1.2.0-beta01' 依赖路径 'MyApp:unspecified' --> 'androidx.fragment:fragment-testing:1.1.0-alpha09' --> 'androidx.test:core:1.1.0'

无法解析 androidx.test:monitor:1.1.1。 要求: 项目:MyApp > androidx.test.ext:junit:1.1.0 找不到满足版本约束的“androidx.test:monitor”版本: 依赖路径 'MyApp:unspecified' --> 'androidx.test.ext:junit:1.1.0' --> 'androidx.test:monitor:1.1.1' 依赖路径 'MyApp:unspecified' --> 'androidx.test:runner:1.2.0-beta01' --> 'androidx.test:monitor:1.2.0-beta01' 依赖路径 'MyApp:unspecified' --> 'androidx.test:core:1.2.0-beta01' --> 'androidx.test:monitor:1.2.0-beta01'

无法解析 androidx.test:core:1.2.0-beta01。 要求: 项目:MyApp > androidx.test.espresso:espresso-intents:3.2.0-beta01 找不到满足版本约束的“androidx.test:core”版本: 依赖路径 'MyApp:unspecified' --> 'androidx.test:core:1.1.0' 约束路径 'MyApp:unspecified' --> 'androidx.test:core:{strictly 1.1.0}' 因为以下原因:esmartliveDebugRuntimeClasspath 使用版本 1.1.0 依赖路径 'MyApp:unspecified' --> 'androidx.test.ext:junit:1.1.0' --> 'androidx.test:core:1.1.0' 依赖路径 'MyApp:unspecified' --> 'androidx.test.espresso:espresso-intents:3.2.0-beta01' --> 'androidx.test:core:1.2.0-beta01' 依赖路径 'MyApp:unspecified' --> 'androidx.fragment:fragment-testing:1.1.0-alpha09' --> 'androidx.test:core:1.1.0'

无法解析 androidx.test:monitor:1.2.0-beta01。 要求: 项目:MyApp > androidx.test:runner:1.2.0-beta01 项目:MyApp > androidx.test:core:1.2.0-beta01 找不到满足版本约束的“androidx.test:monitor”版本: 依赖路径 'MyApp:unspecified' --> 'androidx.test.ext:junit:1.1.0' --> 'androidx.test:monitor:1.1.1' 依赖路径 'MyApp:unspecified' --> 'androidx.test:runner:1.2.0-beta01' --> 'androidx.test:monitor:1.2.0-beta01' 依赖路径 'MyApp:unspecified' --> 'androidx.test:core:1.2.0-beta01' --> 'androidx.test:monitor:1.2.0-beta01'

不知道如何处理这种冲突...有人有同样的问题吗?

【问题讨论】:

    标签: android android-fragments androidx androidx-test


    【解决方案1】:

    这是一个快速的解决方案:

    implementation ("androidx.fragment:fragment-testing:1.1.0-beta01", {         
       exclude group: 'androidx.test', module: 'core'
    })
    

    【讨论】:

    • 我在 gradle 上得到一个编译错误。这种语法真的正确吗?
    • @Rod 你可以问herehere
    • 感谢 Elroid 的友好回复。我最终也找出了正确的语法。现在,关于有问题的问题,在 gradle 中包含这个会使我的片段单元测试失败并出现以下错误:java.lang.NoClassDefFoundError: androidx/test/core/app/ActivityScenario$ActivityAction
    • 如前所述,这是一个快速的解决方案。如果您真的需要该模块,恐怕您将不得不找到另一个答案。
    • @IgorGanapolsky 不包括冲突的core 模块
    猜你喜欢
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 2020-05-14
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 2022-11-29
    相关资源
    最近更新 更多