Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency
2018年05月16日 15:32:44 _Creater_ 閱讀數:10491 標簽: android dependency conflict error 更多
前段時間打開Android studio 在build過程中總會出現以下錯誤
-
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.
在參考了網上的解決辦法:
build->Rebuid-project
后,重新build后發現問題解決了。可是每當新建文件,或者重啟AS后又會出現此類情況,雖然可以解決,但是並不徹底。於是便尋找錯誤根源。仔細閱讀發現問題
Resolved versions for app (26.1.0) and test app (27.1.1) differ
於是便查看app下build.gradle文件,發現並沒有錯誤compileSdkVersion 為26,可是沒有發現27.1.1版本的com.android.support:support-annotations。可是上述信息明顯是版本沖突,於是在external library中尋找

發現了依賴包沖突。於是根據自己的編譯版本刪除多余的包27.1.1(筆者compileSdkVersion 為26),rebuild后問題解決。可是重啟以后問題還會復現。於是上網繼續尋找方法。再嘗試了很多方法后,找到了一個方法解決了該問題。解決方法如下:
在app下的build.gradle文件中的dependences {}中添加如下代碼:
-
androidTestCompile('com.android.support:support-annotations:26.1.0') {
-
-
添加后dependences中結構類似
-
-
androidTestCompile('com.android.support:support-annotations:26.1.0') {
-
-
-
-
最后修改時間2018.5.9 --------------------- 作者:Erorrs 來源:CSDN 原文:https://blog.csdn.net/fighting_2017/article/details/80244982?utm_source=copy 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
android gradle 報錯
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.
解決方法 1
1st
於 app 的 build.gradle 中, 在 android{...} 里添加如下代碼:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1' }
2st
同步 build.gradle 文件
解決方法 2
於 app 的 build.gradle 中, 在 android{...} 里,更改一下屬性,使其為最近版本號,如下
寫於2018/05,自行去官網里尋找適合版本 ——[developer.android.com]
andorid{
... defaultConfig { compileSdkVersion 27 defaultConfig { ... targetSdkVersion 27 ... } ... } ... }
解決方法1:
我們可以重新構建項目(rebuild project)

解決方法2:
我們將依賴中的com.android.support:appcompat-v7版本改為報錯中提到的測試版本:

最后將項目同步一下就可以解決。
總結
新手主義看報錯信息
'.Conflict with dependency 'com.android.support:support-annotations'
說明是依賴沖突,
Resolved versions for app (26.1.0) and test app (27.1.1) differ
給出了沖突的版本,之后要么把沖突的地方降級為 (26.1.0),
要么把整個升級為版本 27