Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Connecting to device with adb over wifi

Context: Nexus 7 Android device (NOT Rooted), Android Studio, Mac OS Yosemite 10.10 Swapping between Eclipse environment and the Android studio appears to have caused the problem, But I don't know how to repair it. All attempts below are after the Eclipse has been shutdown and both computer and device rebooted.

Have seen quite a few S.O. entries but none resolve the intermittent issue of the dreaded 'helpful' message 'unable to connect to 192.168.xx.xx'

It will work successfully sometimes, then "pop" can't connect via wireless Connection. One suggestion I saw was to disconnect the USB after the adb tcpip 5555 command. This worked for me for a while. But not currently!

Have also have tried reboot (computer and device... this has helped before)

Have tried invoking adb tcpip 7612 this alternate port different port This gives me either 'unable to connect to 192.168.xx.xx:5555' OR 'unable to connect to 192.168.xx.xx:7612:7612'

Android docs suggest adb kill-server. And to repeat the steps, Still get the 'helpful' message 'unable to connect to 192.168.0.4'

I have tried specifying that the Nexus use wireless from the Nexus itself (using a terminal app), although I am uncertain if these commands are taking affect as the device is not rooted. setprop service.adb.tcp.port 5555 stop adbd start adbd

Any help in determining what causes the intermittent nature of this connectivity would be greatly appreciated. Thanks

like image 509
redevill Avatar asked Jan 05 '15 19:01

redevill


2 Answers

Your problem seems related to the ADB process started by your IDE. If you want to be sure your ADB connection is working as should and you don't have any error in the commands you are executing I recommend you to use one IntelliJ/Android Studio plugin I've developed to connect your device to your computer over WiFI. Here is the code and here the plugin ready to be used.

In the following gif you can see how it works:

enter image description here

like image 158
Pedro Vicente Gómez Sánchez Avatar answered Sep 30 '22 17:09

Pedro Vicente Gómez Sánchez


I have now managed to connect.

Connect both the android device and the mac to a router that does NOT perform Wifi isolation. Confirmed that the device was connected to the router on the network, AND that I could ping the android device from my mac book.

Then using the following steps: (step - explanation) Plug the device into the Mac, with the developer options USB debugging enabled. (Goto Settings/About Tablet, tap on the build number 7 times, until developer options enabled. Then enable the "USB debugging" option within this new area. You may need to google enabling USB debugging for your device)

Start Android Studio - goto the terminal. Navigate (cd command) to the location where you installed the sdk. (This can be hidden by mac so you may need to start a mac terminal and run "chflags nohidden ~/Library")

adb kill-server - make sure the server is dead adb usb - start adb in usb mode

  • make sure you are watching your device, you may need to acknowledge the usb debugging request.
  • 2 reasons you may not see the "Allow USB debugging", you have checked the "Always allow from this computer" OR there are times it does not show, reason unknown. If this happens - retry above 2 steps and make sure you confirm the "Allow USB debugging"

You will get one of the following messages: * daemon not running. starting it now on port xxxx * * daemon started successfully * restarted in USB mode - OR last line will be error: device unauthorized. Please check the confirmation dialog on your device. (if you get the error, retry it)

adb tcpip 5555 - make sure to acknowledge "Allow USB debugging" again Return message: restarting in TCP mode port: 5555

Make sure you know what the ip address of your device is. (pull down on the wifi in the action bar, click on the connected network to get the list then click on the connected entry, should give you a status including the current ip address)

Now unplug your device from the Mac, run the following command with the ip gathered above. adb connect 192.168.x.x Acknowledge the "Allow USB debugging" again. Return message should be: connected to 192.168.x.x

like image 32
redevill Avatar answered Sep 30 '22 18:09

redevill