天天看點

關于建立項目出現Conflict with dependency 'com.android.support:support-annotations' in project ':app' 錯誤解決方式

在AndroidStudio版本疊代過程中,建立項目可能會出現如下的BUG

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

大概描述就是:App Module下的com.android.support:support-annotations與 androidTest 中依賴的注解版本不一緻。

androidTest下用的是27.1.1,但是可能App主程用的是26.1.0

解決辦法:

在主程module.gradle中添加如下代碼:

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
           

注意configurations.all 的層級需要和android的層級是一緻的。不是嵌套關系

繼續閱讀