I'm trying to learn android espresso.. I followed some basic tutorials and it was working fine. But now I want to do some tests on the android navigation drawer. For that I need to use gradle dependency androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' but it's causing conflict with other dependencies. My gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "my.com.myapp_android"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//material design
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
//zxing
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'
//Testing
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
// Optional -- UI testing with UI Automator
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
//inMarketSDK
//compile group: 'com.inmarket', name: 'm2msdk', version: '2.29', ext: 'aar'
}
Error is something like this:
Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
followed this : link for espresso install
I also tried to exclude annotation dependency :
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
{
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
do below
TL;DR;
New version of
espresso-contrib 2.2.2
library has now dependency oncom.android.support:appcompat-v7:23.1.1
resulting into conflict when using different version ofappcompat-v7
in ourcompile
time dependency like below:To avoid conflict when we exclude
appcompat-v7
dependency fromespresso-contrib
like below it breaks again due to some value dependencies ondesign support
lib.Error:
Root cause:
So, the solution to above problem is to exclude 'design-support' lib dependency from
espresso-contrib
like below:That solves the conflict problem!
LONGER VERSION (in case someone is interested):
To found out the reasons of various conflict issues we face when using `espresso-contrib' library i have created sample app to find out the root cause.
Created App to use 'espresso-contrib' lib version 2.2.1 by adding following lines in
app/build.gradle
file:}
Note: In this case,I am not importing any other support library components like
appcompat-v7,recyclerview-v7,etc
.The dependency graph for the above setup looks like below:
As can be seen that
espresso-contrib 2.2.1
lib has transitive dependencies on version 23.0.1 ofsupport-v4
,recyclerview-v7
,support-annotations
,etc.As i am not defining dependencies for
recyclerview-v7
,support-annotations
in my project the above setup would work just fine.But when we define those as compile dependencies [like below] in our project we get version conflict issues as stated in your question.
To avoid those conflicts we add below line to our espresso-contrib lib:
This makes sure those dependencies aren't downloaded as part of
espresso-contrib
transitive dependencies.Everything runs fine with above setup.No issues!
Changed App's build.gradle to use 'espresso-contrib' lib version 2.2.2 by changing the previous build.gradle file:
But when i build project using above setup..build fails with error posted in question..
Error:
So, looking at error i added one more line to above build.gradle:
But that doesn't resolves the conflict issue and i get value dependencies error posted in comments.
So i check for dependency graph of my app again:
As can be seen now that
espresso-contrib 2.2.2
lib has now transitive dependency oncom.android.support:design:23.1.1
causing the above conflict.So, we need to add below line inside
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
block:This resolves the conflict issue in lib version 2.2.2!