Running tests on remote adb server

时间:2019-03-19 15:12:57

标签: android android-gradle adb

Trying to run gradle tests on remote adb server.

ADB_SERVER_SOCKET=tcp:host:port and ADB_DEVICE=emulator-5554 works fine for adb, but not gradle.

Looks like ANDROID_ADB_SERVER_PORT works for gradle, but I didn't find a way to set adb server host.

1 个答案:

答案 0 :(得分:1)

我可以从Android Studio源代码看出来,它不支持读取主机地址。它是硬编码的:

/**
 * Instantiates sSocketAddr with the address of the host's adb process.
 */
private static void initAdbSocketAddr() {
    try {
        sAdbServerPort = getAdbServerPort();
        sHostAddr = InetAddress.getByName(DEFAULT_ADB_HOST);
        sSocketAddr = new InetSocketAddress(sHostAddr, sAdbServerPort);
    } catch (UnknownHostException e) {
        // localhost should always be known.
    }
}

Adb读取 ANDROID_ADB_SERVER_ADDRESS ,因此也许可以扩展Android Studio以使用此env变量。

目前的解决方法可能是使用iptables将流量从127.0.0.1:5037重新路由到您想要的任何流量,请参见answer here