在android中,主机PC可以在ip 10.0.2.2上访问。有没有办法通过USB插入设备来访问主机?

时间:2015-03-02 17:24:43

标签: android

在android中,主机PC可以在ip 10.0.2.2(according to this doc)上访问。有没有办法通过USB插入设备来访问主机?

上下文是我正在跳跃运行一个wiremock服务器作为gradle构建过程的一部分来帮助测试。 Wiremock doesn't run in android没有重要的工作,所以在主机PC上运行它似乎是更简单的选择。

1 个答案:

答案 0 :(得分:0)

WireMock现在可以在2016年1月的Android应用中运行,无需执行任何特殊操作。此问题已于几周前通过{{3的WireMock 2.0.8-beta修复}}。我已更新2.0-beta branch并创建了WireMock GitHub issue

这使您无需担心通过USB连接主机。您可以在Android设备上运行WireMock服务器并连接到localhost。

以下是您需要使用它的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+'