在運(yùn)行項(xiàng)目的時(shí)候,遇到以下問題
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.
經(jīng)過多番查找,大致看來是 app中依賴庫(kù)與test中依賴庫(kù)版本不一致的問題,最后發(fā)現(xiàn)是因?yàn)?build.gradle 統(tǒng)一管理后,我在 Library的build.gradle中有測(cè)試包的依賴代碼:
//庫(kù)依賴
dependencies{
//......
testImplementation librarys.testImplementation_test_junit
androidTestImplementation librarys.androidTestImplementation_support_runner
androidTestImplementation librarys.androidTestImplementation_support_espresso
//......
}
然后在 app-module的build.gradle中也有測(cè)試包的依賴代碼:
dependencies{
//......
testImplementation librarys.testImplementation_test_junit
androidTestImplementation librarys.androidTestImplementation_support_runner
androidTestImplementation librarys.androidTestImplementation_support_espresso
//......
我第三方庫(kù)的依賴是用config.build統(tǒng)一管理的,此時(shí)報(bào)錯(cuò)是因?yàn)長(zhǎng)ibary和app中都對(duì)測(cè)試包進(jìn)行了依賴,重復(fù)了,需要?jiǎng)h除app-module中的
testImplementation librarys.testImplementation_test_junit
androidTestImplementation librarys.androidTestImplementation_support_runner
androidTestImplementation librarys.androidTestImplementation_support_espresso
測(cè)試包依賴,然后重新clean,rebuild即可。
打完收工。