在我的robotium android测试中尝试启动WireMockServer时获得以下堆栈跟踪。 可能是两个版本的Apache Http客户端之间存在冲突,但我还没有设法解决它。 有什么想法吗?
java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLSocketFactory.<init>
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSocketFactory(HttpClientFactory.java:110)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClientConnectionManagerWithSSLSettings(HttpClientFactory.java:88)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:54)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:70)
at com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.<init>(ProxyResponseRenderer.java:58)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:96)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:140)
at com.me.expertsystem.AcceptanceTest.setUp(AcceptanceTest.java:63)
答案 0 :(得分:1)
我担心自2015年第一场比赛以来,WireMock不支持Android。正在跟踪github issue中的支持进展情况。
它在Roboelectric测试中运行良好,因为它们在标准JVM中运行,因此您至少可以将它用于测试的这一方面。
答案 1 :(得分:1)
WireMock现在可在2016年1月的Android应用中使用。这是几周前使用2.0-beta branch的WireMock 2.0.8-beta修复的。我已更新WireMock GitHub issue并创建了sample project showing it working。
以下是您需要使用它的build.gradle依赖项:
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+'