java.lang.IncompatibleClassChangeError when including espresso-contrib:2.0

后端 未结 4 757
谎友^
谎友^ 2021-01-04 12:14

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

相关标签:
4条回答
  • 2021-01-04 12:41

    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:

    • java.lang.IncompatibleClassChangeError when using espresso-contrib
    • Resolving conflicts between main and test APK
    0 讨论(0)
  • 2021-01-04 12:43

    Maybe you forgot to add testInstrumentationRunner android.support.test.runner.AndroidJUnitRunner" in a defaultConfig{}

    0 讨论(0)
  • 2021-01-04 12:56

    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

    0 讨论(0)
  • 2021-01-04 12:58

    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

    0 讨论(0)
提交回复
热议问题