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

后端 未结 4 759
谎友^
谎友^ 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: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

提交回复
热议问题