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:42

Assume you saved adb path into your Windows environment path

  1. Activate debug mode in Android

  2. Connect to PC via USB

  3. Open command prompt type: adb tcpip 5555

  4. Disconnect your tablet or smartphone from pc

  5. Open command prompt type: adb connect IPADDRESS (IPADDRESS is the DHCP/IP address of your tablet or smartphone, which you can find by Wi-Fi -> current connected network)

Now in command prompt you should see the result like: connected to xxx.xxx.xxx.xxx:5555

查看更多
梦寄多情
3楼-- · 2018-12-31 01:42

Use the adbwireless app to enable the phone, then use adb connect from the Windows machine to talk to it. The adbwireless app on the phone tells you how to connect to it, giving the IP address and everything.

The much less fun alternative is to connect via USB, tell the phone to use TCPIP via adb tcpip 5555, then disconnect USB, then use adb connect. This is much harder because this way you have to figure out the IP address of the phone yourself (adbwireless tells you the IP), you have to connect via USB, and you have to run adb tcpip (adbwireless takes care of that too).

So: install adbwireless on your phone. Use it. It is possible, I do it routinely on Linux and on Windows.

查看更多
谁念西风独自凉
4楼-- · 2018-12-31 01:43

First you must connect your device via USB

Then connect your device to WIFI and get the IP address. While still connect via usb type this in command line or via Android Studio Terminal

adb tcpip 5555
adb connect <device IP>:5555

You will see these messages:

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

Now remove the USB cable and you will still see your logcat as normal

Done. Enjoy

查看更多
刘海飞了
5楼-- · 2018-12-31 01:44

I did get this working. Didn't use any usb cable.

  • app adb wireless.
  • Run it. That will set ip and port; Then in dos

    cd C:\Program Files\Android\android-sdk\platform-tools adb connect "192.168.2.22:8000 "enter"
    

Connected.

查看更多
临风纵饮
6楼-- · 2018-12-31 01:44

adb can communicate with adb server over tcp socket. you can verify this by telnet.

$ telnet 127.0.0.1 5037
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
000chost:version
OKAY00040020

generally, command has the format %04x%s with <message.length><msg> the following is the ruby command witch sends adb command cmd against tcp socket socket

def send_to_adb(socket, cmd)
  socket.printf("%04x%s", cmd.length, cmd)
end

the first example sends the command host:version which length is 12(000c in hex). you can enjoy more exciting command like framebuffer: which takes screenshot from framebuffer as you can guess from its name.

查看更多
永恒的永恒
7楼-- · 2018-12-31 01:45

As Brian said:

According to a post on xda-developers, you can enable ADB over WiFi from the device with the commands

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

If you have USB access already, it is even easier to switch to using WiFi. 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

To tell the ADB daemon return to listening over USB

adb usb

There are also several apps on the Android Market that automate this process.

It works.You just need to access the android shell and type those commands...

One other (easier) solution is on the Market: adbWireless, it will automatically set your phone.

Root is required! for both...

查看更多
登录 后发表回答