![](/img/trans.png)
[英]Warning:Conflict with dependency 'com.android.support:support-annotations'
[英]Conflict with dependency 'com.android.support:support-annotations' in project
片刻之后,我返回使用Android Studio。 創建新項目時遇到此問題
錯誤:任務':app:preDebugAndroidTestBuild'的執行失敗。
與項目“:app”中的依賴項“ com.android.support:support-annotations”沖突。 應用(26.1.0)和測試應用(27.1.1)的已解決版本不同。 有關詳細信息,請參見https://d.android.com/r/tools/test-apk-dependency-conflicts.html 。
我發現了許多解決此問題的方法,但沒有一個起作用。 更新到23.3.0后,Android支持庫錯誤
我的依賴項中有這些:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support:support-annotations:27.1.1'
}
您需要對appCompat和support-annotations使用相同版本的支持庫。 因此,將依賴項從以下位置更改:
implementation 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile 'com.android.support:support-annotations:27.1.1'
至
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
然后,嘗試使用以下命令從espresso中排除現有的支持注釋:
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
我有相同版本的support-annotations模塊沖突。 所不同的是,我嘗試減少測試庫使用的版本。
dependencies {
def withoutSupportAnnotations = {exclude group: 'com.android.support', module: 'support-annotations'}
androidTestImplementation 'com.android.support.test:runner:1.0.2', withoutSupportAnnotations
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', withoutSupportAnnotations}
這個可重用的變量幫助了我。 還要測試:runner和espresso使用相同版本的注釋(在我的情況下為27.2.1 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.