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

One additional note (learned the hard way): You should not have your company VPN-connection active at the same time...

查看更多
姐姐魅力值爆表
3楼-- · 2018-12-31 01:36

For PC users:

Step 1:
You have to enable Developer options in your Android phone.
You can enable Developer options using this way.
• Open Settings> About> Software Information> More.
• Then tap “Build number” seven times to enable Developer options.
• Go back to Settings menu and now you'll be able to see “Developer options” there.
• Tap it and turn on USB Debugging from the menu on the next screen.

Step 2:

Open cmd and type adb.
if you find that adb is not valid command then you have to add a path to the environment variable.

•First go to you SDK installed folder
Follow this path and this path is just for an example. D:\softwares\Development\Andoird\SDK\sdk\platform-tools\; D:\softwares\Development\Andoird\SDK\sdk\tools;
• Now search on windows system advanced setting

enter image description here

Open the Environment variable.

enter image description here

then open path and paste the following path this is an example.
You SDK path is different from mine please use yours. D:\softwares\Development\Andoird\SDK\sdk\platform-tools\;
D:\softwares\Development\Andoird\SDK\sdk\tools;

enter image description here

Step 3:

Open cmd and type adb. if you still see that adb is not valid command then your path has not set properly follow above steps.

enter image description here

Now you can connect your android phone to PC.

Open cmd and type adb devices and you can see your device. Find you phone ip address.

enter image description here

Type:- adb tcpip 5555

enter image description here

Get the IP address of your phone

adb shell netcfg

Now,

adb connect "IP address of your phone"

Now run your android project and if not see you device then type again adb connect IP address of your phone

enter image description here

enter image description here

For Linux and MAC User:

Step 1: open terminal and install adb using

sudo apt-get install android-tools-adb android-tools-fastboot

Connect your phone via USB cable to PC. Type following command in terminal

adb tcpip 5555

Using adb, connect your android phone ip address.

Remove your phone.

查看更多
余生无你
4楼-- · 2018-12-31 01:36

You Need to do following things:

  • First, Add ADB to your environment path.
  • From your CLI type this command adb connect YOUR_DEVICE_IP:PORT_NUMBER (example adb connect 192.168.100.100:5555)
查看更多
素衣白纱
5楼-- · 2018-12-31 01:38

If you want to easily connect your device to run, debug or deploy your Android apps over WiFi you can use an open source IntelliJ Plugin I've developed. Here is the code and here the plugin ready to be used.

The usage is quite simple. Here you have a gif:

enter image description here

查看更多
何处买醉
6楼-- · 2018-12-31 01:40

Here's an extension to Brian's answer using Bluetooth:

  1. On Linux, use Blueman to share PC internet with your device via Bluetooth:

    $ sudo apt-get install blueman
    $ blueman-manager
    Pair them: Search devices after enabling Bluetooth
    on your phone and making it visible
    $ blueman-services
    Network > [X] Network Access Point (NAP)
    Your Phone > Settings > Bluetooth > Paired Device > [X] Internet access
    
  2. Use the Bluetooth network for ADB commands:

    $ adb tcpip 5555
    $ adb connect $(adb shell ip -f inet addr show bt-pan | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n1):5555
    

Once done to return to USB mode:

$ adb disconnect
$ adb usb

Note: Bluetooth 3.0 and 4.0 can go up to 24 Mbit/s.

查看更多
皆成旧梦
7楼-- · 2018-12-31 01:41

I needed to get both USB and TCPIP working for ADB (don't ask), so I did the following (using directions others have posted from xda-developers)

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