与项目中的依赖项'com.android.support:support-annotations'冲突



过了一会儿,我又回到了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 和支持注释使用相同的支持库版本。因此,请将依赖项从:

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'

然后,尝试通过以下方式从浓缩咖啡中排除现有的支持注释:

androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: '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}

这个可重用的变量帮助了我。 另外test:runnerespresso使用相同的注释版本(在我的例子中为27.2.1(

最新更新