How can I connect to Android with ADB over TCP?
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?
Manual Process
From your device, if it is rooted
According to a post on xda-developers, you can enable ADB over Wi-Fi from the device with the commands:
su
setprop service.adb.tcp.port 5555
stop adbd
start adbd
And you can disable it and return ADB to listening on USB with
setprop service.adb.tcp.port -1
stop adbd
start adbd
From a computer, if you have USB access already (no root required)
It is even easier to switch to using Wi-Fi, if you already have USB. From a command line on the computer that has the device connected via USB, issue the commands
adb tcpip 5555
adb connect 192.168.0.101:5555
Be sure to replace 192.168.0.101
with the IP address that is actually assigned to your device.
You can find the IP address of a tablet in two ways:
Manual IP Discovery:
Go into Android's WiFi settings, click the menu button in the action bar (the vertical ellipsis), hit Advanced and see the IP address at the bottom of the screen.
Use ADB to discover IP:
Execute the following command via adb:
adb shell ip -f inet addr show wlan0
To tell the ADB daemon return to listening over USB
adb usb
Apps to automate the process
There are also several apps on Google Play that automate this process. A quick search suggests adbWireless, WiFi ADB and ADB WiFi. All of these require root access, but adbWireless requires fewer permissions.
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-windowstools
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.
Connect device via USB and make sure debugging is working, then run:
adb tcpip 5555
adb connect <DEVICE_IP_ADDRESS>:5555
Disconnect USB and proceed with wireless debugging.
When you're done and want to switch back to USB debugging, run:
adb -s <DEVICE_IP_ADDRESS>:5555
To find the IP address of your device, go to Settings > Wi-Fi > Advanced > IP Address
on your device or run adb shell netcfg
.
No root required. Only one device can be debugged at a time.
See this XDA post.
The adb
command is located in the platform-tools
folder of the Android SDK.
上一篇: 调解员模式(也可能是MVP?)