0

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'
}
Community
  • 1
  • 1
Lomado
  • 3
  • 1

2 Answers2

0

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'
})
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • This syntax of excluding doesnt work in for me. I've found an other one, see my answer below – Sergio Jul 18 '18 at 10:31
0

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)

Sergio
  • 558
  • 5
  • 10