我正在尝试调试摩托罗拉Droid上的应用程序,但通过USB连接到设备时遇到一些困难。我的开发服务器是一个在Hyper-V中运行的Windows 7 64位虚拟机,因此我无法在来宾或主机中通过USB直接连接。
我安装了两种不同的USB over TCP解决方案,但连接似乎有问题,因为ADB监视器反复报告“devicemonitor failed to start monitoring”。是否有一种方法可以直接从开发机器上的客户端连接到设备上的守护程序,使用网络而不是USB连接或其他可行的选项?
我正在尝试调试摩托罗拉Droid上的应用程序,但通过USB连接到设备时遇到一些困难。我的开发服务器是一个在Hyper-V中运行的Windows 7 64位虚拟机,因此我无法在来宾或主机中通过USB直接连接。
我安装了两种不同的USB over TCP解决方案,但连接似乎有问题,因为ADB监视器反复报告“devicemonitor failed to start monitoring”。是否有一种方法可以直接从开发机器上的客户端连接到设备上的守护程序,使用网络而不是USB连接或其他可行的选项?
当前回答
我需要让USB和TCPIP都为ADB工作(不要问),所以我做了以下工作(使用其他人从xda开发人员发布的指示)
使用adb shell:
su
#Set the port number for adbd
setprop service.adb.tcp.port 5555
#Run the adbd daemon *again* instead of doing stop/start, so there
#are two instances of adbd running.
adbd &
#Set the port back to USB, so the next time ADB is started it's
#on USB again.
setprop service.adb.tcp.port -1
exit
其他回答
您还可以使用SSH本地端口转发。但它仍然需要USB电缆。使用USB将手机连接到运行sshd的计算机(主机)。在远程(来宾)pc上启动能够端口转发/隧道的SSH客户端。例子:
plink -L 5037:localhost:5037 <host_IP_address>
我使用这种构造将设备连接到虚拟机。Eltima USB转以太网不够稳定(调试期间超时)。
SSH隧道免费工作,更可靠。
假设您已将adb路径保存到Windows环境路径中
在Android中激活调试模式通过USB连接到PC打开命令提示符类型:adb-tcpip 5555断开平板电脑或智能手机与电脑的连接打开命令提示符类型:adb connect IPADDRESS(IPADDRESS是平板电脑或智能手机的DHCP/IP地址,可以通过Wi-Fi->当前连接的网络找到)
现在在命令提示符中,您应该看到这样的结果:connected to xxx.xxx.xxx.xxxx:55555
我不知道如何在没有任何USB连接的情况下连接设备,但如果您设法在另一台计算机上连接,您可以通过发出以下命令将adbd切换到TCP模式
adb tcpip <port>
通过以下方式从终端连接到您的设备:
adb connect <ip>:<port>
也许也可以从设备上的终端切换到TCP模式。
以下是Brian使用蓝牙回答的扩展:
在Linux上,使用Blueman通过蓝牙与设备共享PC互联网:$sudo apt-get安装blueman$blueman经理配对:启用蓝牙后搜索设备并使其可见$blueman服务网络>[X]网络接入点(NAP)您的手机>设置>蓝牙>配对设备>[X]Internet访问使用蓝牙网络执行ADB命令:$adb tcpip 5555$adb connect$(adb shell ip-f inet addr show bt pan | egrep-o'[0-9]+\.[0-9]+\.[0-10]+\.[0-9]'| head-n1):5555
完成后返回USB模式:
$ adb disconnect
$ adb usb
注意:蓝牙3.0和4.0最高可达24 Mbit/s。
我创建了一个批处理文件,用于通过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