1、問題:
新創建項目的時候突然出現
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.
這個問題,但是這個問題不影響程序運行,只是每次編譯都會出現。
2、解決過程
根據com.android.support:support-annotations 提示,查看External Libraies下,發現有兩個版本 一個是26.1.0一個是27.1.1
猜測是與程序運行SDK版本有關
當前版本
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
當前compileSdkVersion 爲26 所以每次運行時編譯的是 26.1.0的版本,但是系統找到的一直是最新的27.1.1版本 ,因此出現以上異常提示。
(猜測系統會找最新的的版本,因爲在大白項目中未出現異常,查看External Libraies發現最新的版本爲26.10,compileSdkVersion 爲26。)
3、解決方案1:
將compileSdkversion和targetVersion統一升級到27+ 再次編譯解決。
解決方案2:
在app build.gradle的dependencies 中添加
androidTestCompile('com.android.support:support-annotations:26.1.0') {
force = true
}