我需要在连接到同一网络中另一台机器的设备上部署测试应用程序并发出命令。
我通读了http://developer.android.com/tools/help/adb.html#directingcommands但我找不到答案。
我尝试使用 adb connect <remote machine IP>
但我得到了unable to connect
错误。
有没有办法部署应用程序并执行adb
连接到远程系统的设备上的命令?
最佳答案
来自adb
tag wiki :
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
- A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
- A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
- A daemon, which runs as a background process on each emulator or device instance.
adb connect
命令用于连接本地adb
服务器 adbd
网络连接设备上的守护进程。但是你想要的是连接本地adb
客户端 到远程(在另一个系统上运行)adb
服务器。 adb
的默认行为可执行文件是连接到 adb
的本地实例服务器。如果没有找到它会尝试启动一个。这种方法适用于所有开发都在单个系统上完成的大多数环境。但在更复杂的环境中,它可能会导致 adb
的多个实例。 服务器 正在启动。因为adbd
daemon 只支持连接到单个 adb
一次服务器 - 该设备将被一个系统识别,并且在其他任何地方都将丢失。
所以为了adb
要在那些更复杂的配置中可靠地识别设备,您需要告诉 adb
停止猜测并手动指定 adb
的哪一部分(即服务器或客户端)应该在哪个系统上运行。
首先确保您拥有相同且足够新的 adb
版本(最新的谷歌官方版本通常效果最好)安装在本地和远程系统上。那没有 adb
服务器当前正在任一系统上运行。
然后启动 adb server
的一个实例在远程系统(您将要插入设备的系统)上使用此命令:
adb -a -P <PORT_NUMBER> nodaemon server
现在你可以强制adb
本地系统上的客户端通过添加 -H <REMOTE_IP> -P <PORT_NUMBER>
来使用其他(远程)服务器而不是启动自己的(本地)实例给你的adb
命令:
adb -H <REMOTE_IP> -P <PORT_NUMBER> devices
或者,设置 ANDROID_ADB_SERVER_ADDRESS=<REMOTE_IP>
和 ANDROID_ADB_SERVER_PORT=<PORT_NUMBER>
客户端的环境变量将使您不必指定 <REMOTE_IP>
和 <PORT_NUMBER>
对于每个 adb
命令。
如果省略 <PORT_NUMBER>
将默认为 5037
.
adb
的官方内置解决方案编排不是 SSH 隧道 的互斥替代方案 - 它只是解决了另一个更重要的问题。您可以在此之上添加隧道以增加额外的安全性或帮助解决多站点网络环境中的路由问题。但是单靠隧道无法解决所有adb
连接问题。
同样适用于虚拟化环境 - 运行多个 adb server
host 和 guest 系统之间的实例也会导致 adb
连接问题。
关于android - 如何在连接到远程系统的设备上部署和执行应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245597/