I have a subclass of android.support.v7.widget.RecyclerView. It works fine when I use the application and testing.
However, when I include espresso-contrib in my gra
please use Newest Gradle Plugin (is not a stable version)
Starting with 2.0.0 of the Android Gradle Plugin, Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions.
To make the build succeed, just add a dependency for the newer version to the build.gradle
for example:
androidTestCompile "com.android.support:recyclerview-v7:${supportLibVersion}"
reference:
Maybe you forgot to add testInstrumentationRunner android.support.test.runner.AndroidJUnitRunner" in a defaultConfig{}
Espresso dependency is out of date. Reported and will be fixed in the future. https://code.google.com/p/android-test-kit/issues/detail?id=139
You can try to add that at the bottom of your gradle file (after every char)
/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}
/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
println "Excluding compile dependency: ${compileDependency.getName()}"
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
}
}
It's from the Android-testing project on github
Source: https://github.com/googlecodelabs/android-testing/blob/master/app/build.gradle#L96