我正在尝试调试摩托罗拉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

其他回答

首先,您必须通过USB连接设备

然后将设备连接到WIFI并获取IP地址。当仍然通过usb连接时,在命令行或通过Android Studio终端键入

adb tcpip 5555
adb connect <device IP>:5555

您将看到以下消息:

restarting in TCP mode port: 5555
connected to 172.11.0.16:5555

现在卸下USB电缆,您仍会看到logcat正常

完成。享受

我创建了一个批处理文件,用于通过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添加到环境路径中。在CLI中键入以下命令adb connect your_DEVICE_IP:PORT_NUMBER(示例adb connect192.168.100.100:5555)

我确实做到了。没有使用任何usb电缆。

应用程序adb无线。运行它。这将设置ip和端口;然后在dos中cd C:\Program Files\Android\Android-sdk\platform tools adb connect“192.168.2.22:8000”enter“

有联系的。

如果您想通过WiFi轻松连接设备以运行、调试或部署Android应用程序,可以使用我开发的开源IntelliJ插件。这里是代码,这里是可以使用的插件。

用法很简单。这里有一张gif图: