How can I connect to Android with ADB over TCP?

2018-12-31 00:43发布

I am attempting to debug an application on a Motorola Droid, but I am having some difficulty connecting to the device via USB. My development server is a Windows 7 64-bit VM running in Hyper-V, and so I cannot connect directly via USB in the guest or from the host.

I installed a couple of different USB-over-TCP solutions, but the connection appears to have issues since the ADB monitor reports "devicemonitor failed to start monitoring" repeatedly. Is there a way to connect directly from the client on the development machine to the daemon on the device using the network instead of the USB connection or possibly another viable options?

30条回答
宁负流年不负卿
2楼-- · 2018-12-31 01:28

I do not know how to connect the device without any USB connection at all, but if you manage to connect it maybe at another computer you can switch the adbd to TCP mode by issuing

adb tcpip <port>

from a terminal and connect to your device over wifi from any PC on the network by:

adb connect <ip>:<port>

Maybe it is also possible to switch to TCP mode from a terminal on the device.

查看更多
查无此人
3楼-- · 2018-12-31 01:31

You can also use SSH local port forwarding. But it still involves a USB cable. Connect your phone using USB to a computer (host) with an sshd running. On a remote (guest) pc start an SSH client capable of portforwarding/tunneling. Example:

plink -L 5037:localhost:5037 <host_IP_address>

I use this construction to connect my device to a virtual machine. Eltima USB to Ethernet wasn't stable enough (timeouts during debug).

SSH tunneling works for free and is more reliable.

查看更多
与君花间醉酒
4楼-- · 2018-12-31 01:31

I just followed following steps and it started working, so that i can connect to my android device.

Step 1: Open the terminal Window in Android Devices and execute the following command.

  1. su -- To switch to super user.
  2. setprop service.adb.tcp.port 5555 - To specify the tcp Port - 5555 is the port number here
  3. stop adbd - To stop the adbb service.
  4. start adbd - To start adbd service.

Step 2: Through ADB, Execute the bellow command.(From the path where ADB is configured)

adb connect 10.10.10.50:5555 - Here 10.10.10.50 is the IP address of the android device and 5555 is the port number.

查看更多
皆成旧梦
5楼-- · 2018-12-31 01:32
adb tcpip 5555

Weird, but this only works for me if I have the USB cable connected, then I can unplug the usb and go for it with everything else adb.

and the same when returning to usb,

adb usb

will only work if usb is connected.

It doesn't matter if I issue the

setprop service.adb.tcp.port 5555

or

setprop service.adb.tcp.port -1

then stop & start adbd, I still need the usb cable in or it doesn't work.

So, if my ADB over usb wasn't working, I bet I wouldn't be able to enable ADB over WiFi either.

查看更多
不再属于我。
6楼-- · 2018-12-31 01:34

This is really simple if your phone is rooted.

Download a terminal emulator from Google Play (there are lots that are free). Make sure that your Android device is connected to your Wi-Fi and get the Wi-Fi IP address. Open the terminal program and type:

su
setprop service.adb.tcp.port 5555
stop adbd
start adbd

Now go to your computer (assuming that you are using Windows) and create a shortcut on the desktop for "cmd.exe" (without the quotations).

Right click on the cmd shortcut and choose "Run as Administrator"

Change to your android-sdk-windows\tools folder

Type:

adb connect ***wifi.ip.address***:5555

(example: adb connect 192.168.0.105:5555)

adb should now say that you are connected.

Note: if you are too fast to give the connect command it may fail. So try at least two times five seconds apart before you say this doesn't work.

查看更多
冷夜・残月
7楼-- · 2018-12-31 01:34

I put together a batch file for automatic enabling and connecting ADB via TCP, to a device connected via USB. With it you don't have to put in the IP manually.

@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
查看更多
登录 后发表回答