无法使用 Proguard 在 Android 项目上设置 Wiremock(重复 Zip 条目错误)
Unable to Setup Wiremock on Android Project with Proguard (Duplicate Zip Entry error)
我现在一直在阅读所有帖子,此时我真的很挣扎。
我试图在我的 android 项目中使用 WireMock 来帮助进行测试。不过,Proguard总有话要说。
我的 gradle 依赖文件是这样的:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// Fine Tuned Google Play Services
compile "com.google.android.gms:play-services-ads:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-plus:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-identity:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-location:${PLAY_SERVICES_VERSION}"
// we need base for "Google Cloud Messaging"
compile "com.google.android.gms:play-services-base:${PLAY_SERVICES_VERSION}"
// Android Wear
compile "com.google.android.gms:play-services-wearable:${PLAY_SERVICES_VERSION}"
compile 'pl.tajchert:exceptionwear:0.1.2'
// Handheld application
compile 'de.greenrobot:greendao:1.3.7'
compile "com.android.support:support-v13:21.0.3"
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
compile "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
compile "com.android.support:support-annotations:${SUPPORT_LIB_VERSION}"
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup:otto:1.3.6'
compile 'com.github.johnkil.android-robototextview:robototextview:2.4.0'
compile 'com.mixpanel.android:mixpanel-android:4.5.3@aar'
compile('com.crashlytics.sdk.android:crashlytics:2.2.3@aar') {
transitive = true;
}
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile "com.hannesdorfmann.fragmentargs:annotation:${FRAGARGS_VERSION}"
apt "com.hannesdorfmann.fragmentargs:processor:${FRAGARGS_VERSION}"
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'com.adjust.sdk:adjust-android:4.0.4'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-math3:3.5'
compile 'se.emilsjolander:stickylistheaders:2.6.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.afollestad:material-dialogs:0.7.5.1'
provided 'javax.annotation:jsr250-api:1.0' // to enable guava proguard
// only on debug
compile 'com.facebook.stetho:stetho:1.1.1'
compile 'com.facebook.stetho:stetho-okhttp:1.1.1'
// Dagger related dependencies
compile 'com.google.dagger:dagger:2.0'
apt 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
// androidTest dependencies
androidTestCompile 'com.google.dagger:dagger:2.0'
androidTestApt 'com.google.dagger:dagger-compiler:2.0'
androidTestProvided 'org.glassfish:javax.annotation:10.0-b28'
androidTestCompile('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.2') {
exclude group: 'org.mockito', module: 'mockito-core'
}
androidTestCompile ('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile ('com.github.tomakehurst:wiremock:1.56:standalone') {
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'commons-io', module: 'commons-io'
exclude group: 'commons-cli', module: 'commons-cli'
}
// Unit testing dependencies
testCompile 'junit:junit:4.12'
testCompile('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
}
我的测试混淆文件是这样的:
# Proguard rules run against the test module (split since Gradle plugin v 1.1.0)
-dontobfuscate
-ignorewarnings
# Specific classes that common test libs warn about
-dontwarn java.beans.**
-dontwarn javax.lang.model.element.Modifier
-dontwarn org.apache.tools.ant.**
-dontwarn org.assertj.core.internal.cglib.asm.util.TraceClassVisitor
-dontwarn org.easymock.**
-dontwarn org.jmock.core.**
-dontwarn org.w3c.dom.bootstrap.**
-dontwarn sun.misc.Unsafe
-dontwarn sun.reflect.**
-dontwarn wiremock.**
-dontwarn org.mockito.**
-dontwarn org.custommonkey.**
-dontwarn android.test.**
-dontwarn com.jayway.**
-dontwarn android.support.test.**
-dontwarn org.skyscreamer.**
-dontwarn org.slf4j.**
-dontwarn com.github.tomakehurst.wiremock.http.ResponseDefinition
-dontwarn com.google.common.net.InternetDomainName
我的主要项目依赖:
+--- com.google.android.gms:play-services-ads:7.0.0
| +--- com.google.android.gms:play-services-base:7.0.0
| | \--- com.android.support:support-v4:22.0.0 -> 22.2.0
| | \--- com.android.support:support-annotations:22.2.0 -> 22.1.1
| \--- com.google.android.gms:play-services-analytics:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-plus:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-identity:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-location:7.0.0
| +--- com.google.android.gms:play-services-base:7.0.0 (*)
| \--- com.google.android.gms:play-services-maps:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-wearable:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- pl.tajchert:exceptionwear:0.1.2
+--- de.greenrobot:greendao:1.3.7
+--- com.android.support:support-v13:21.0.3
| \--- com.android.support:support-v4:21.0.3 -> 22.2.0 (*)
+--- com.android.support:appcompat-v7:22.1.1 -> 22.2.0
| \--- com.android.support:support-v4:22.2.0 (*)
+--- com.android.support:support-v4:22.1.1 -> 22.2.0 (*)
+--- com.android.support:support-annotations:22.1.1
+--- de.hdodenhof:circleimageview:1.2.2
+--- com.squareup.retrofit:retrofit:1.9.0
| \--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp-urlconnection:2.3.0
| \--- com.squareup.okhttp:okhttp:2.3.0
| \--- com.squareup.okio:okio:1.3.0
+--- com.squareup.okhttp:okhttp:2.3.0 (*)
+--- com.squareup.picasso:picasso:2.5.2
+--- com.squareup:otto:1.3.6
+--- com.github.johnkil.android-robototextview:robototextview:2.4.0
| \--- com.android.support:appcompat-v7:22.1.0 -> 22.2.0 (*)
+--- com.mixpanel.android:mixpanel-android:4.5.3
+--- com.crashlytics.sdk.android:crashlytics:2.2.3
| +--- com.crashlytics.sdk.android:answers:1.1.2
| | \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.0
| +--- io.fabric.sdk.android:fabric:1.3.0
| \--- com.crashlytics.sdk.android:beta:1.1.2
| \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.0
+--- com.facebook.android:facebook-android-sdk:4.0.1
| +--- com.android.support:support-v4:[21,22) -> 22.2.0 (*)
| \--- com.parse.bolts:bolts-android:1.1.4
+--- com.hannesdorfmann.fragmentargs:annotation:2.1.0
+--- com.sothree.slidinguppanel:library:3.0.0
| +--- com.android.support:support-v4:19.1.0 -> 22.2.0 (*)
| \--- com.nineoldandroids:library:2.4.0
+--- com.adjust.sdk:adjust-android:4.0.4
+--- commons-io:commons-io:2.4
+--- org.apache.commons:commons-math3:3.5
+--- se.emilsjolander:stickylistheaders:2.6.0
+--- com.melnykov:floatingactionbutton:1.3.0
| +--- com.android.support:support-annotations:21.0.3 -> 22.1.1
| +--- com.android.support:recyclerview-v7:21.0.3 -> 22.2.0
| | +--- com.android.support:support-annotations:22.2.0 -> 22.1.1
| | \--- com.android.support:support-v4:22.2.0 (*)
| \--- com.nineoldandroids:library:2.4.0
+--- com.jakewharton:butterknife:6.1.0
+--- com.afollestad:material-dialogs:0.7.5.1
| +--- com.android.support:support-v4:22.2.0 (*)
| +--- com.android.support:appcompat-v7:22.2.0 (*)
| +--- com.android.support:recyclerview-v7:22.2.0 (*)
| \--- com.android.support:support-annotations:22.2.0 -> 22.1.1
+--- com.facebook.stetho:stetho:1.1.1
| +--- commons-cli:commons-cli:1.2
| \--- com.google.code.findbugs:jsr305:2.0.1
+--- com.facebook.stetho:stetho-okhttp:1.1.1
| +--- com.squareup.okhttp:okhttp:2.2.0 -> 2.3.0 (*)
| +--- com.facebook.stetho:stetho:1.1.1 (*)
| \--- com.google.code.findbugs:jsr305:2.0.1
+--- com.google.dagger:dagger:2.0
| \--- javax.inject:javax.inject:1
+--- :pullToRefresh:
+--- project :PhotoViewLib
| \--- com.android.support:support-v4:22.0.0 -> 22.2.0 (*)
+--- project :h19sharedsources
| +--- com.google.android.gms:play-services-wearable:6.+ -> 7.0.0 (*)
| \--- com.android.support:support-annotations:21.0.3 -> 22.1.1
+--- project :h19base
+--- javax.annotation:jsr250-api:1.0
\--- org.glassfish:javax.annotation:10.0-b28
我的测试项目依赖:
+--- com.google.dagger:dagger:2.0
| \--- javax.inject:javax.inject:1
+--- org.mockito:mockito-core:1.10.19
| \--- org.objenesis:objenesis:2.1
+--- com.google.dexmaker:dexmaker-mockito:1.2
| \--- com.google.dexmaker:dexmaker:1.2
+--- com.squareup.assertj:assertj-android:1.0.0
| \--- org.assertj:assertj-core:1.6.1
+--- com.squareup.spoon:spoon-client:1.1.2
+--- com.android.support.test.espresso:espresso-core:2.1
| +--- com.android.support.test:rules:0.2
| | \--- com.android.support.test:runner:0.2
| | +--- junit:junit-dep:4.10
| | | \--- org.hamcrest:hamcrest-core:1.1
| | +--- com.android.support.test:exposed-instrumentation-api-publish:0.2
| | \--- com.android.support:support-annotations:22.0.0 -> 22.1.1
| +--- com.squareup:javawriter:2.1.1
| +--- org.hamcrest:hamcrest-integration:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- com.android.support.test.espresso:espresso-idling-resource:2.1
| +--- org.hamcrest:hamcrest-library:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:2.0.1
| +--- com.android.support.test:runner:0.2 (*)
| +--- javax.annotation:javax.annotation-api:1.2
| \--- org.hamcrest:hamcrest-core:1.1
\--- com.github.tomakehurst:wiremock:1.56
+--- org.slf4j:slf4j-api:1.7.6
+--- xmlunit:xmlunit:1.5
+--- org.mortbay.jetty:jetty:6.1.26
| +--- org.mortbay.jetty:jetty-util:6.1.26
| \--- org.mortbay.jetty:servlet-api:2.5-20081211
+--- org.skyscreamer:jsonassert:1.2.3
+--- com.jayway.jsonpath:json-path:0.8.1
| +--- net.minidev:json-smart:1.1.1
| \--- commons-lang:commons-lang:2.6
+--- com.fasterxml.jackson.core:jackson-annotations:2.4.2
+--- com.fasterxml.jackson.core:jackson-core:2.4.2
+--- com.google.guava:guava:18.0
+--- net.sf.jopt-simple:jopt-simple:4.7
\--- com.fasterxml.jackson.core:jackson-databind:2.4.2
+--- com.fasterxml.jackson.core:jackson-annotations:2.4.0 -> 2.4.2
\--- com.fasterxml.jackson.core:jackson-core:2.4.2
我的错误输出:
Note: there were 149 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/maven/org.mortbay.jetty/jetty/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/org.mortbay.jetty/jetty/pom.properties])
Warning:can't write resource [META-INF/maven/org.mortbay.jetty/jetty/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/org.mortbay.jetty/jetty/pom.xml])
Warning:can't write resource [META-INF/maven/com.google.guava/guava/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.google.guava/guava/pom.properties])
Warning:can't write resource [META-INF/maven/com.google.guava/guava/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.google.guava/guava/pom.xml])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
Warning:can't write resource [META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties])
Warning:can't write resource [META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml])
Warning:can't write resource [META-INF/services/com.fasterxml.jackson.core.JsonFactory] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/services/com.fasterxml.jackson.core.JsonFactory])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
:app:proguardStagingDebugAndroidTest FAILED
Error:Execution failed for task ':app:proguardStagingDebugAndroidTest'.
> java.io.IOException: Can't write [/Users/fabiocarballo/h19-android/app/build/intermediates/classes-proguard/androidTest/staging/debug/classes.jar] (Can't read [/Users/fabiocarballo/.gradle/caches/modules-2/files-2.1/com.github.tomakehurst/wiremock/1.56/4f6c96ea684cfa6375bbd7d2c2e4c8a47ccf615d/wiremock-1.56-standalone.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [wiremock-1.56-standalone.jar:org/custommonkey/xmlunit/AbstractNodeTester.class]))
谢谢大家。非常欢迎任何帮助!
不要试图与 Wiremock 和 Android 工作室搏斗,
而是将 wiremock 作为一个并行进程独立启动。
下载此代码库
https://github.com/nenick/android-gradle-template
运行 Scripts/run-tests.sh 来自项目根目录
然后 运行 你的项目。
每当您想自定义响应时,请尝试 restful 调用 wiremock 的管理面板
在 http://wiremock.org/running-standalone.html 中搜索单词 "curl",从 expresso 或 robolectric 测试或 [=35= 进行调用(通过 HttpClient 或 AndroidAnnotations REST) ]宁申请
您实际上可以从 gradle 开始 wiremock(假设在连接测试之前)
task startWire(type: Exec) {
commandLine 'sh', '..\Scripts\start-wiremock.sh','&'
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebugAndroidTest') {
task.dependsOn startWire
}
}
WireMock 现在可以在 Android Studio 的 Android 应用程序中运行,截至 2016 年 1 月。几周前,2.0-beta branch. I've updated that WireMock GitHub issue and have created a sample project showing it working.
的 WireMock 2.0.8-beta 已修复此问题
以下是您需要使用它的 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+'
相关堆栈溢出问题:NoSuchMethodError when using WireMock in an Android integration test
我现在一直在阅读所有帖子,此时我真的很挣扎。
我试图在我的 android 项目中使用 WireMock 来帮助进行测试。不过,Proguard总有话要说。
我的 gradle 依赖文件是这样的:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// Fine Tuned Google Play Services
compile "com.google.android.gms:play-services-ads:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-plus:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-identity:${PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-location:${PLAY_SERVICES_VERSION}"
// we need base for "Google Cloud Messaging"
compile "com.google.android.gms:play-services-base:${PLAY_SERVICES_VERSION}"
// Android Wear
compile "com.google.android.gms:play-services-wearable:${PLAY_SERVICES_VERSION}"
compile 'pl.tajchert:exceptionwear:0.1.2'
// Handheld application
compile 'de.greenrobot:greendao:1.3.7'
compile "com.android.support:support-v13:21.0.3"
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
compile "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
compile "com.android.support:support-annotations:${SUPPORT_LIB_VERSION}"
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup:otto:1.3.6'
compile 'com.github.johnkil.android-robototextview:robototextview:2.4.0'
compile 'com.mixpanel.android:mixpanel-android:4.5.3@aar'
compile('com.crashlytics.sdk.android:crashlytics:2.2.3@aar') {
transitive = true;
}
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile "com.hannesdorfmann.fragmentargs:annotation:${FRAGARGS_VERSION}"
apt "com.hannesdorfmann.fragmentargs:processor:${FRAGARGS_VERSION}"
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'com.adjust.sdk:adjust-android:4.0.4'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-math3:3.5'
compile 'se.emilsjolander:stickylistheaders:2.6.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.afollestad:material-dialogs:0.7.5.1'
provided 'javax.annotation:jsr250-api:1.0' // to enable guava proguard
// only on debug
compile 'com.facebook.stetho:stetho:1.1.1'
compile 'com.facebook.stetho:stetho-okhttp:1.1.1'
// Dagger related dependencies
compile 'com.google.dagger:dagger:2.0'
apt 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
// androidTest dependencies
androidTestCompile 'com.google.dagger:dagger:2.0'
androidTestApt 'com.google.dagger:dagger-compiler:2.0'
androidTestProvided 'org.glassfish:javax.annotation:10.0-b28'
androidTestCompile('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.2') {
exclude group: 'org.mockito', module: 'mockito-core'
}
androidTestCompile ('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile ('com.github.tomakehurst:wiremock:1.56:standalone') {
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'commons-io', module: 'commons-io'
exclude group: 'commons-cli', module: 'commons-cli'
}
// Unit testing dependencies
testCompile 'junit:junit:4.12'
testCompile('org.mockito:mockito-core:1.10.19') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
}
我的测试混淆文件是这样的:
# Proguard rules run against the test module (split since Gradle plugin v 1.1.0)
-dontobfuscate
-ignorewarnings
# Specific classes that common test libs warn about
-dontwarn java.beans.**
-dontwarn javax.lang.model.element.Modifier
-dontwarn org.apache.tools.ant.**
-dontwarn org.assertj.core.internal.cglib.asm.util.TraceClassVisitor
-dontwarn org.easymock.**
-dontwarn org.jmock.core.**
-dontwarn org.w3c.dom.bootstrap.**
-dontwarn sun.misc.Unsafe
-dontwarn sun.reflect.**
-dontwarn wiremock.**
-dontwarn org.mockito.**
-dontwarn org.custommonkey.**
-dontwarn android.test.**
-dontwarn com.jayway.**
-dontwarn android.support.test.**
-dontwarn org.skyscreamer.**
-dontwarn org.slf4j.**
-dontwarn com.github.tomakehurst.wiremock.http.ResponseDefinition
-dontwarn com.google.common.net.InternetDomainName
我的主要项目依赖:
+--- com.google.android.gms:play-services-ads:7.0.0
| +--- com.google.android.gms:play-services-base:7.0.0
| | \--- com.android.support:support-v4:22.0.0 -> 22.2.0
| | \--- com.android.support:support-annotations:22.2.0 -> 22.1.1
| \--- com.google.android.gms:play-services-analytics:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-plus:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-identity:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-location:7.0.0
| +--- com.google.android.gms:play-services-base:7.0.0 (*)
| \--- com.google.android.gms:play-services-maps:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- com.google.android.gms:play-services-wearable:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- pl.tajchert:exceptionwear:0.1.2
+--- de.greenrobot:greendao:1.3.7
+--- com.android.support:support-v13:21.0.3
| \--- com.android.support:support-v4:21.0.3 -> 22.2.0 (*)
+--- com.android.support:appcompat-v7:22.1.1 -> 22.2.0
| \--- com.android.support:support-v4:22.2.0 (*)
+--- com.android.support:support-v4:22.1.1 -> 22.2.0 (*)
+--- com.android.support:support-annotations:22.1.1
+--- de.hdodenhof:circleimageview:1.2.2
+--- com.squareup.retrofit:retrofit:1.9.0
| \--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp-urlconnection:2.3.0
| \--- com.squareup.okhttp:okhttp:2.3.0
| \--- com.squareup.okio:okio:1.3.0
+--- com.squareup.okhttp:okhttp:2.3.0 (*)
+--- com.squareup.picasso:picasso:2.5.2
+--- com.squareup:otto:1.3.6
+--- com.github.johnkil.android-robototextview:robototextview:2.4.0
| \--- com.android.support:appcompat-v7:22.1.0 -> 22.2.0 (*)
+--- com.mixpanel.android:mixpanel-android:4.5.3
+--- com.crashlytics.sdk.android:crashlytics:2.2.3
| +--- com.crashlytics.sdk.android:answers:1.1.2
| | \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.0
| +--- io.fabric.sdk.android:fabric:1.3.0
| \--- com.crashlytics.sdk.android:beta:1.1.2
| \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.0
+--- com.facebook.android:facebook-android-sdk:4.0.1
| +--- com.android.support:support-v4:[21,22) -> 22.2.0 (*)
| \--- com.parse.bolts:bolts-android:1.1.4
+--- com.hannesdorfmann.fragmentargs:annotation:2.1.0
+--- com.sothree.slidinguppanel:library:3.0.0
| +--- com.android.support:support-v4:19.1.0 -> 22.2.0 (*)
| \--- com.nineoldandroids:library:2.4.0
+--- com.adjust.sdk:adjust-android:4.0.4
+--- commons-io:commons-io:2.4
+--- org.apache.commons:commons-math3:3.5
+--- se.emilsjolander:stickylistheaders:2.6.0
+--- com.melnykov:floatingactionbutton:1.3.0
| +--- com.android.support:support-annotations:21.0.3 -> 22.1.1
| +--- com.android.support:recyclerview-v7:21.0.3 -> 22.2.0
| | +--- com.android.support:support-annotations:22.2.0 -> 22.1.1
| | \--- com.android.support:support-v4:22.2.0 (*)
| \--- com.nineoldandroids:library:2.4.0
+--- com.jakewharton:butterknife:6.1.0
+--- com.afollestad:material-dialogs:0.7.5.1
| +--- com.android.support:support-v4:22.2.0 (*)
| +--- com.android.support:appcompat-v7:22.2.0 (*)
| +--- com.android.support:recyclerview-v7:22.2.0 (*)
| \--- com.android.support:support-annotations:22.2.0 -> 22.1.1
+--- com.facebook.stetho:stetho:1.1.1
| +--- commons-cli:commons-cli:1.2
| \--- com.google.code.findbugs:jsr305:2.0.1
+--- com.facebook.stetho:stetho-okhttp:1.1.1
| +--- com.squareup.okhttp:okhttp:2.2.0 -> 2.3.0 (*)
| +--- com.facebook.stetho:stetho:1.1.1 (*)
| \--- com.google.code.findbugs:jsr305:2.0.1
+--- com.google.dagger:dagger:2.0
| \--- javax.inject:javax.inject:1
+--- :pullToRefresh:
+--- project :PhotoViewLib
| \--- com.android.support:support-v4:22.0.0 -> 22.2.0 (*)
+--- project :h19sharedsources
| +--- com.google.android.gms:play-services-wearable:6.+ -> 7.0.0 (*)
| \--- com.android.support:support-annotations:21.0.3 -> 22.1.1
+--- project :h19base
+--- javax.annotation:jsr250-api:1.0
\--- org.glassfish:javax.annotation:10.0-b28
我的测试项目依赖:
+--- com.google.dagger:dagger:2.0
| \--- javax.inject:javax.inject:1
+--- org.mockito:mockito-core:1.10.19
| \--- org.objenesis:objenesis:2.1
+--- com.google.dexmaker:dexmaker-mockito:1.2
| \--- com.google.dexmaker:dexmaker:1.2
+--- com.squareup.assertj:assertj-android:1.0.0
| \--- org.assertj:assertj-core:1.6.1
+--- com.squareup.spoon:spoon-client:1.1.2
+--- com.android.support.test.espresso:espresso-core:2.1
| +--- com.android.support.test:rules:0.2
| | \--- com.android.support.test:runner:0.2
| | +--- junit:junit-dep:4.10
| | | \--- org.hamcrest:hamcrest-core:1.1
| | +--- com.android.support.test:exposed-instrumentation-api-publish:0.2
| | \--- com.android.support:support-annotations:22.0.0 -> 22.1.1
| +--- com.squareup:javawriter:2.1.1
| +--- org.hamcrest:hamcrest-integration:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- com.android.support.test.espresso:espresso-idling-resource:2.1
| +--- org.hamcrest:hamcrest-library:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:2.0.1
| +--- com.android.support.test:runner:0.2 (*)
| +--- javax.annotation:javax.annotation-api:1.2
| \--- org.hamcrest:hamcrest-core:1.1
\--- com.github.tomakehurst:wiremock:1.56
+--- org.slf4j:slf4j-api:1.7.6
+--- xmlunit:xmlunit:1.5
+--- org.mortbay.jetty:jetty:6.1.26
| +--- org.mortbay.jetty:jetty-util:6.1.26
| \--- org.mortbay.jetty:servlet-api:2.5-20081211
+--- org.skyscreamer:jsonassert:1.2.3
+--- com.jayway.jsonpath:json-path:0.8.1
| +--- net.minidev:json-smart:1.1.1
| \--- commons-lang:commons-lang:2.6
+--- com.fasterxml.jackson.core:jackson-annotations:2.4.2
+--- com.fasterxml.jackson.core:jackson-core:2.4.2
+--- com.google.guava:guava:18.0
+--- net.sf.jopt-simple:jopt-simple:4.7
\--- com.fasterxml.jackson.core:jackson-databind:2.4.2
+--- com.fasterxml.jackson.core:jackson-annotations:2.4.0 -> 2.4.2
\--- com.fasterxml.jackson.core:jackson-core:2.4.2
我的错误输出:
Note: there were 149 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang-2.6.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/maven/org.mortbay.jetty/jetty/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/org.mortbay.jetty/jetty/pom.properties])
Warning:can't write resource [META-INF/maven/org.mortbay.jetty/jetty/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/org.mortbay.jetty/jetty/pom.xml])
Warning:can't write resource [META-INF/maven/com.google.guava/guava/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.google.guava/guava/pom.properties])
Warning:can't write resource [META-INF/maven/com.google.guava/guava/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.google.guava/guava/pom.xml])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
Warning:can't write resource [META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties])
Warning:can't write resource [META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml])
Warning:can't write resource [META-INF/services/com.fasterxml.jackson.core.JsonFactory] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/services/com.fasterxml.jackson.core.JsonFactory])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
Warning:can't write resource [META-INF/LICENSE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/LICENSE])
Warning:can't write resource [META-INF/NOTICE] (Duplicate zip entry [wiremock-1.56-standalone.jar:META-INF/NOTICE])
:app:proguardStagingDebugAndroidTest FAILED
Error:Execution failed for task ':app:proguardStagingDebugAndroidTest'.
> java.io.IOException: Can't write [/Users/fabiocarballo/h19-android/app/build/intermediates/classes-proguard/androidTest/staging/debug/classes.jar] (Can't read [/Users/fabiocarballo/.gradle/caches/modules-2/files-2.1/com.github.tomakehurst/wiremock/1.56/4f6c96ea684cfa6375bbd7d2c2e4c8a47ccf615d/wiremock-1.56-standalone.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [wiremock-1.56-standalone.jar:org/custommonkey/xmlunit/AbstractNodeTester.class]))
谢谢大家。非常欢迎任何帮助!
不要试图与 Wiremock 和 Android 工作室搏斗, 而是将 wiremock 作为一个并行进程独立启动。
下载此代码库
https://github.com/nenick/android-gradle-template
运行 Scripts/run-tests.sh 来自项目根目录
然后 运行 你的项目。
每当您想自定义响应时,请尝试 restful 调用 wiremock 的管理面板
在 http://wiremock.org/running-standalone.html 中搜索单词 "curl",从 expresso 或 robolectric 测试或 [=35= 进行调用(通过 HttpClient 或 AndroidAnnotations REST) ]宁申请
您实际上可以从 gradle 开始 wiremock(假设在连接测试之前)
task startWire(type: Exec) {
commandLine 'sh', '..\Scripts\start-wiremock.sh','&'
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebugAndroidTest') {
task.dependsOn startWire
}
}
WireMock 现在可以在 Android Studio 的 Android 应用程序中运行,截至 2016 年 1 月。几周前,2.0-beta branch. I've updated that WireMock GitHub issue and have created a sample project showing it working.
的 WireMock 2.0.8-beta 已修复此问题以下是您需要使用它的 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+'
相关堆栈溢出问题:NoSuchMethodError when using WireMock in an Android integration test