运行 在远程 adb 服务器上测试

Running tests on remote adb server

正在尝试 运行 gradle 在远程 adb 服务器上进行测试。

ADB_SERVER_SOCKET=tcp:host:portADB_DEVICE=emulator-5554 适用于 adb,但不适用于 gradle。

看起来 ANDROID_ADB_SERVER_PORT 适用于 gradle,但我没有找到设置 adb 服务器主机的方法。

我从 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 以使用此环境变量。

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