Resolved versions for app (25.3.1) and test app (25.4.0) dif

在運行項目的時候,遇到以下問題

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (25.3.1) and test app (25.4.0) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

經過多番查找,大致看来是 app中依赖库与test中依赖库版本不一致的问题,最后发现是因为 build.gradle 统一管理后,我在 Library的build.gradle中有测试包的依赖代码:

    //库依赖
    dependencies{
//......

    testImplementation librarys.testImplementation_test_junit
    androidTestImplementation librarys.androidTestImplementation_support_runner
    androidTestImplementation librarys.androidTestImplementation_support_espresso

//......

然后在 app-module的build.gradle中也有测试包的依赖代码:

    dependencies{
//......

    testImplementation librarys.testImplementation_test_junit
    androidTestImplementation librarys.androidTestImplementation_support_runner
    androidTestImplementation librarys.androidTestImplementation_support_espresso

//......

我第三方库的依赖是用config.build统一管理的,此时报错是因为Libary和app中都对测试包进行了依赖,重复了,需要删除app-module中的

    testImplementation librarys.testImplementation_test_junit
    androidTestImplementation librarys.androidTestImplementation_support_runner
    androidTestImplementation librarys.androidTestImplementation_support_espresso

测试包依赖,然后重新clean,rebuild即可。

打完收工。

此文为转载,原文https://www.jishux.com/plus/view-688287-1.html

猜你喜欢

转载自blog.csdn.net/u011435933/article/details/80265264
app