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?
I've found a convenient method that i would like to share.
For Windows
Having USB Access Once
No root required
Connect your phone and pc to a hotspot or run portable hotspot from your phone and connect your pc to it.
Get the ip of your phone as prescribed by brian (Wont need if you're making hotspot from your phone)
Open Notepad
Write these
Change the location given above to where your pc contains the abd.exe file
Change the ip to your phone ip.
Note : The IP given above is the basic IP of an android device when it makes a hotspot. If you are connecting to a wifi network and if your device's IP keeps on changing while connecting to a hotspot every time, you can make it static by configuring within the wifi settings. Google it.
Now save the file as ABD_Connect.bat (MS-DOS batch file).
Save it somewhere and refer a shortcut to Desktop or Start button.
Connect through USB once, and try running some application. After that whenever you want to connect wirelessly, double click the shortcut.
Note : Sometimes you need to open the shortcut each time you debug the application. So making a shortcut key for the shortcut in desktop will be more convenient. I've made a shortcut key like
Ctrl+Alt+S
. So whenever i wish to debug, i'll pressShift+F9
andCtrl+Alt+S
Note : If you find device=null error on cmd window, check your IP, it might have changed.
To connect your tablet using TCP port. Make sure your system and device is connected to same network.
adb tcpip 5555
adb connect 192.168.1.2
this is your device IP addressConnected using port forward Try to do port forwarding,
adb forward tcp:
<PC port>
tcp:<device port>
like:
If you get message error: device not found connect a usb device to system then follow same procedure.
for a rooted device
Bash util function:
From
adb --help
:That's a command-line option by the way.
You should try connecting the phone to your Wi-Fi, and then get its IP address from your router. It's not going to work on the cell network.
The port is 5554.
From a computer on a non-rooted device
(Note that this can be done using a rooted device as well, but you can use a shell on a rooted device which doesn't require a USB connection)
Firstly, open command prompt (CMD). If you use Android Studio or IntelliJ there is a console included in there you can use.
If possible, open the SDK location, right click, and press "start command prompt here". Not all have this option so you have to do this (/these) commands as well:
Change the drive (if applicable)
And access the sdk and platform tools. Replace this path with your SDK location:
Now you have access to the Android debug bridge.
Now, with the device connected to the computer, do:
Where is the port you want to connect to (default is
5555
) and is the IP of the device you want to connect to.Please note:
5555
is the default port and just writing the IP address connects it. If you use a custom port you can at least improve the security a bit. USB debugging over wifi can be abused, but only if the device is connected to the computer who wants to abuse the device. Using a non-default port at least makes it a bit harder to connect.If you use a custom port, make sure to add it after the IP. Writing no port connects to
5555
and if you didn't use that the connection will fail.You can find the IP address of a device in two ways:
Depending on your device, the exact names may vary. Open settings and go to About device -> Status -> IP address
Use ADB to get the IP
From the console, do:
And once you are finished with the connection, you can disconnect the device from your computer by doing:
Or no IP to disconnect all devices. If you used a custom port, you must specify which port to disconnect from. The default is 5555 here as well.
To disable the port (if that is something you want to do) you do this command with the device connected:
Or you can restart the device to remove the tcpip connection
From a computer on a rooted device
Firstly, you need access to the shell. You either connect the device using a usb cable and use
adb shell
or download an app from Google Play, FDroid, or some other source.Then you do:
And to connect the device, you do as in the non-rooted version by doing
adb connect <ip>:<port>
.And if you want to disable the port and go back to USB listening:
You can also use an Android Studio plugin to do it for you (don't remember the name right now), and for rooted users there's also the option of downloading an Android app to set up the phone connection (adb connect is probably still required).
Some phones have a setting in developer options (this applies to some unrooted phones, though probably some rooted phones too) that allows for toggling ADB over wifi from the device itself without root or a computer connection to start it. Though there are few phones that have that
To switch between TCP and USB modes with just one command, you can add this to
/init.rc
:And now you can use property
service.adb.tcp.enable
to enable or disable listening on port 5555. Runnetstat
to check whether it's listening. As you can see it will also trigger if you do wish to changeservice.adb.tcp.port
manually.