NoSuchMethodError when using WireMock in an Android integration test

前端 未结 2 1965
借酒劲吻你
借酒劲吻你 2020-12-21 19:35

Got the following stack trace when trying to start a WireMockServer in my robotium android test. Might be a conflict between 2 versions of Apache Http client, but I did not

相关标签:
2条回答
  • 2020-12-21 19:51

    I'm afraid that as of 1st Match 2015 WireMock does not support Android. Progress towards support is being tracked in this github issue.

    It does work quite well in Roboelectric tests because these run in a standard JVM, so you may be able use it for that aspect of testing at least.

    0 讨论(0)
  • 2020-12-21 19:54

    WireMock now works in an Android app as of January 2016. This is fixed as of a couple of weeks ago with WireMock 2.0.8-beta from the 2.0-beta branch. I've updated that WireMock GitHub issue and have created a sample project showing it working.

    Here are the build.gradle dependencies you'll need to use it:

    androidTestCompile("com.github.tomakehurst:wiremock:2.0.8-beta") {
        //Allows us to use the Android version of Apache httpclient
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    
        //Resolves the Duplicate Class Exception
        //Error:Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
        //       > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class
        exclude group: 'asm', module: 'asm'
    
        //Fixes conflict with Android's version
        //Warning:Dependency org.json:json:20090211 is ignored for debugAndroidTest as it may be conflicting with the internal version provided by Android.
        //In case of problem, please repackage with jarjar to change the class packages
        exclude group: 'org.json', module: 'json'
    }
    androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5+'
    
    0 讨论(0)
提交回复
热议问题