我正在尝试调试摩托罗拉Droid上的应用程序,但通过USB连接到设备时遇到一些困难。我的开发服务器是一个在Hyper-V中运行的Windows 7 64位虚拟机,因此我无法在来宾或主机中通过USB直接连接。

我安装了两种不同的USB over TCP解决方案,但连接似乎有问题,因为ADB监视器反复报告“devicemonitor failed to start monitoring”。是否有一种方法可以直接从开发机器上的客户端连接到设备上的守护程序,使用网络而不是USB连接或其他可行的选项?


当前回答

我创建了一个批处理文件,用于通过TCP自动启用ADB并将其连接到通过USB连接的设备。有了它,您不必手动输入IP。

@echo off
setlocal

REM Use a default env variable to find adb if possible
if NOT "%AndroidSDK%" == "" set PATH=%PATH%;%AndroidSDK%\platform-tools

REM If off is first parameter then we turn off the tcp connection.
if "%1%" == "off" goto off

REM Set vars
set port=%1
set int=%2
if "%port%" == "" set port=5557
if "%int%" == "" set int=wlan0

REM Enable TCP
adb -d wait-for-device tcpip %port%

REM Get IP Address from device
set shellCmd="ip addr show %int% | grep 'inet [0-9]{1,3}(\.[0-9]{1,3}){3}' -oE | grep '[0-9]{1,3}(\.[0-9]{1,3}){3}' -oE"
for /f %%i in ('adb wait-for-device shell %shellCmd%') do set IP=%%i

REM Connect ADB to device
adb connect %IP%:%port%

goto end

:fail
echo adbWifi [port] [interface]
echo adbWifi off
goto end

:off
adb wait-for-device usb

:end

其他回答

在我的系统中,情况如下:

在我的Linux shell中的Android设备上,一个简单的“ifconfig”没有给我IP地址。我必须键入:

如果配置eth0

-or-

网络配置文件

获取我的IP地址。(我知道eth0已配置,因为我在dmesg中看到了它。)然后我执行了以下操作:

setprop服务.adb.tcp.port-1

停止adbd

启动adbd

然后在我的Win7盒子(运行Eclipse3.7.1的盒子)上

\android sdk\平台工具>

而不以管理员身份运行。然后我做了一个

adb连接12.345.678.90

我从来没有放过端口

adb tcpip 5555

它说找不到该设备,然后我的“adb设备”列表中没有任何内容。也就是说,只有当我不执行上面的tcpip命令时,它才有效。

我可以做一个“adb外壳”,并破坏我的Android设备。但我的Android设备现在没有出现在我的运行->运行配置->目标选项卡中。另一方面,如果我将目标选项卡设置为自动。然后,当我通过run->run运行我的应用程序时,它确实会在我的Android设备上运行,即使我的安卓设备甚至没有被列为我的目标之一。

我创建了一个批处理文件,用于通过TCP自动启用ADB并将其连接到通过USB连接的设备。有了它,您不必手动输入IP。

@echo off
setlocal

REM Use a default env variable to find adb if possible
if NOT "%AndroidSDK%" == "" set PATH=%PATH%;%AndroidSDK%\platform-tools

REM If off is first parameter then we turn off the tcp connection.
if "%1%" == "off" goto off

REM Set vars
set port=%1
set int=%2
if "%port%" == "" set port=5557
if "%int%" == "" set int=wlan0

REM Enable TCP
adb -d wait-for-device tcpip %port%

REM Get IP Address from device
set shellCmd="ip addr show %int% | grep 'inet [0-9]{1,3}(\.[0-9]{1,3}){3}' -oE | grep '[0-9]{1,3}(\.[0-9]{1,3}){3}' -oE"
for /f %%i in ('adb wait-for-device shell %shellCmd%') do set IP=%%i

REM Connect ADB to device
adb connect %IP%:%port%

goto end

:fail
echo adbWifi [port] [interface]
echo adbWifi off
goto end

:off
adb wait-for-device usb

:end

我在同一个问题上是结构化的,但一个简单的破解adb反向tcp:<PORT>tcp:<PORT>对我有效。它允许系统接受tcp请求。

感谢您的阅读

您还可以使用SSH本地端口转发。但它仍然需要USB电缆。使用USB将手机连接到运行sshd的计算机(主机)。在远程(来宾)pc上启动能够端口转发/隧道的SSH客户端。例子:

plink -L 5037:localhost:5037 <host_IP_address>

我使用这种构造将设备连接到虚拟机。Eltima USB转以太网不够稳定(调试期间超时)。

SSH隧道免费工作,更可靠。

我发现其他答案令人困惑。使用adbWireless要简单得多:

http://ppareit.github.com/AdbConnect/

只需在手机上安装一个应用程序,通过wifi切换调试,安装一个eclipse插件,就完成了。