简体   繁体   中英

Conflict with dependency 'com.android.support:support-annotations' in project

After a short time I return to use Android Studio. When I create a new project I encounter this problem

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.

I found many solutions to this problem but none of them worked. Android support library error after updating to 23.3.0

I have these in my dependencies:

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'
}

You need to use the same version of support library for appCompat and support-annotations. So, change the dependencies from:

implementation 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile 'com.android.support:support-annotations:27.1.1'

to

implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'

Then, try to excluding existing support-annotations from espresso with:

androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

I'v got the same version conflict of support-annotations module. The difference was that i've tried to decrease version which is used by test libs.

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}

This reusable variable helped me. Also test:runner and espresso use the same version of annotations ( 27.2.1 in my case)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM