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.

Edit: Following is taken from the comments

Following are 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:3.0.2' 
    androidTestImplementation 'com.android.support:support-annotations:27.1.1' 
}
Sagar
  • 23,903
  • 4
  • 62
  • 62
sarika
  • 47
  • 1
  • 6
  • can you update your question with` build.gradle` ? – Sagar Apr 29 '18 at 12:29
  • 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:3.0.2' androidTestImplementation 'com.android.support:support-annotations:27.1.1' } – sarika Apr 29 '18 at 14:17
  • These are the app level dependencies i implemented inside the app. i added the last gradle androidTestImplementation 'com.android.support:support-annotations:27.1.1' but error is not resolved. – sarika Apr 29 '18 at 14:20
  • I have answered the question, you can check – Sagar Apr 29 '18 at 14:23

2 Answers2

1

Based on the documentation:

Both your app APK and its test APK share the same classpath. So, you can get a build error if both APKs depend on different versions of the same library.

So the fix would be to change your

com.android.support:appcompat-v7:26.1.0

to

com.android.support:appcompat-v7:27.1.1

Sagar
  • 23,903
  • 4
  • 62
  • 62
  • Great! Remember to click on tick button so that it is approved and others can benefit too – Sagar Apr 29 '18 at 14:30
1

you can also go for this one.

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

instead of this,

androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
Sagar Bhagwat
  • 103
  • 1
  • 9