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

On my system it went like this:

On my Android device in my Linux shell, a simple "ifconfig" did not give me my IP address. I had to type:

ifconfig eth0

-or-

netcfg

to get my IP address. (I knew eth0 was configured because I saw it in my dmesg.) Then I did the :

setprop service.adb.tcp.port -1

stop adbd

start adbd

Then on my Win7 box (the one running Eclipse 3.7.1). I opened a command prompt to

\android-sdk\platform-tools>

without running as admin. Then I did a

adb connect 12.345.678.90

I never put a port. If I did a

adb tcpip 5555

it said it couldn't find the device then nothing appeared in my "adb devices" list. I.e. it only works if I DON'T do the tcpip command above.

I can do an "adb shell" and mess with my Android Device. But my Android Device does not appear in my Run->Run Configurations->Target tab right now. On the other hand, if I keep the Target Tab set to automatic. Then when I run my app via Run->Run it does run on my Android device even though my Android device is not even listed as one of my targets.

查看更多
墨雨无痕
3楼-- · 2018-12-31 01:20

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.

查看更多
笑指拈花
4楼-- · 2018-12-31 01:20
  1. Connect device via USB and make sure debugging is working, then run:

    adb tcpip 5555
    adb connect <DEVICE_IP_ADDRESS>:5555
    
  2. Disconnect USB and proceed with wireless debugging.

  3. 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.

查看更多
妖精总统
5楼-- · 2018-12-31 01:20

Steps :

  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 adbd service.
  4. start adbd - To start adbd service.

this works perfectly with ssh from my windows PC

I try to do this on the boot on my cyanogen mobile or launch this with plink. With plink I can't launch shell with su right ... sudo or su command not works. On boot I don't know how it's works! My shell program works from ssh with su -c "sh /storage/sdcard1/start_adb.sh" with the last 3 commands (without su --)

Thanks

查看更多
公子世无双
6楼-- · 2018-12-31 01:21

STEP 1.

Make sure both your adb host computer and Android device are on the same Wifi network.

STEP 2.

Connect the Android device with the computer using your USB cable. As soon as you do that, your host computer will detect your device and adb will start running in the USB mode on the computer. You can check the attached devices with adb devices whereas ensure that adb is running in the USB mode by executing adb usb.

$ adb usb
restarting in USB mode
$ adb devices
List of devices attached
ZX1D63HX9R  device


STEP 3.

Restart adb in tcpip mode with this command:

$ adb tcpip 5556
restarting in TCP mode port: 5556


STEP 4.

Find out the IP address of the Android device. There are several ways to do that:

  • WAY: 1 Go to Settings -> About phone/tablet -> Status -> IP address.
  • WAY: 2 Go to the list of Wi-fi networks available. The one to which you’re connected, tap on that and get to know your IP.
  • WAY: 3 Try $ adb shell netcfg.

Now that you know the IP address of your device, connect your adb host to it.

$ adb connect 192.168.0.102:5556
already connected to 192.168.0.102:5556
$ adb devices
List of devices attached
ZX1D63HX9R  device
192.168.0.102:5556  device


STEP 5.

Remove the USB cable and you should be connected to your device. If you don’t see it in adb devices then just reconnect using the previous step’s command:

$ adb connect 192.168.0.102:5556
connected to 192.168.0.102:5556
$ adb devices
List of devices attached
192.168.0.102:5556  device

Either you’re good to go now or you’ll need to kill your adb server by executing adb kill-server and go through all the steps again once more.

Hope that helps!


Reference:

查看更多
宁负流年不负卿
7楼-- · 2018-12-31 01:21

I find the other answers confusing. Far simpler to use adbWireless:

http://ppareit.github.com/AdbConnect/

Simply install an app on your phone to toggle debugging over wifi, install an eclipse plug-in and you're done.

查看更多
登录 后发表回答