Android espresso-contrib gradle build failing
For some reason, it has also started to happen to me out of the blue.
The only thing that solved it was to invalidate caches and restart
TL;DR;
New version of espresso-contrib 2.2.2
library has now dependency on com.android.support:appcompat-v7:23.1.1
resulting into conflict when using different version of appcompat-v7
in our compile
time dependency like below:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}
To avoid conflict when we exclude appcompat-v7
dependency from espresso-contrib
like below it breaks again due to some value dependencies on design support
lib.
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'appcompat-v7'
}
Error:
Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.
Root cause:
This is because the
design
support lib has dependency onappcompat-v7
.
So,when we exclude 'appcompat-v7' module fromespresso-contrib
dependencies(like above) , thedesign
support lib downloaded as part of transitive dependency ofespresso-contrib
lib couldn't find the compatible version ofappcompat-v7 lib(23.1.1)
it is using internally in its resources files and thus gives out the above error.
So, the solution to above problem is to exclude 'design-support' lib dependency from espresso-contrib
like below:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'design'
}
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.
Step 1:Using Espresso-Contrib Lib version 2.2.1
Created App to use 'espresso-contrib' lib version 2.2.1 by adding following lines in app/build.gradle
file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
}
Note: In this case,I am not importing any other support library components likeappcompat-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.
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
To avoid those conflicts we add below line to our espresso-contrib lib:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
This makes sure those dependencies aren't downloaded as part of espresso-contrib
transitive dependencies.
Everything runs fine with above setup.No issues!
Step 2: Using Espresso-Contrib lib version 2.2.2
Changed App's build.gradle to use 'espresso-contrib' lib version 2.2.2 by changing the previous build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
testCompile 'junit:junit:4.12'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
}
But when i build project using above setup..build fails with error posted in question..
Error:
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.
So, looking at error i added one more line to above build.gradle:
exclude module: 'appcompat-v7' (inside androidTestCompile block of espresso-contrib)
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 on com.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:
exclude module: 'design'
This resolves the conflict issue in lib version 2.2.2!