Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Consistent Way to Connect ADB over TCP

I am debugging an Android app that usually crashes when I plug into an Arduino it is supposed to be communicating with. Consequently, I need to get a wireless connection to the device's logcat, which is what brought me to ADB over TPC as seen on the Android developers webpage.

The recommended process is:

C:\Users\User> cd AppData\Local\Android\sdk\platform-tools
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb kill-server
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb tcpip 5555
restarting in TCP mode port: 5555
C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb connect 10.20.5.160:5555

However, the typical response is:

unable to connect to 10.20.5.160:5555: cannot connect to 10.20.5.160:5555: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

I could not consistently get a connection between a PC and mobile device. Over the course of three weeks using several networks and devices, I could only connect two times out of an agonizing many attempts.

I have dug deep into the posted questions on stackoverflow and tried literally every recommended alteration to getting an adb connection, from using an Android Studio plugin to forwarding ports to trying several other ports to toggling my device's internet. I still could not get a connection more than a fraction of a percent of the time.

When I look at the network state of my device after adb tpip <port>, I find no evidence of the device trying to look for a connection:

C:\Users\User\AppData\Local\Android\sdk\platform-tools> adb shell
j3ltevzw:/ $ netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 ::ffff:10.20.5.160:4214 ::ffff:173.194.196.188: ESTABLISHED
udp     4288      0 adb shell ip -f inet addr show wlan0:68          10.20.5.1:67            ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State           I-Node Path
  ...    ...   ...        ...         ...                   ...
  ...    ...   ...        ...         ...                   ...

Also, when I try to ping my device, I usually get:

C:\Users\Benjamin\AppData\Local\Android\sdk\platform-tools> ping 10.20.5.160

Pinging 10.20.5.160 with 32 bytes of data:
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.
Reply from 10.20.5.232: Destination host unreachable.

Ping statistics for 10.20.5.160:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)

What I am looking for is a process or file that can be run and consistently open a tcp adb connection, or at least explain what about my setup is invalid. Ideas?

Update 1:

I have started a bounty on this question. I feel like the problem with the ADB software used to make connection for debugging is two fold:

  1. adb tcpip <port> does not always invoke the mobile device to listen on the specified port

  2. adb connect <ip>:<port>, I am assuming, is not given permission by the network to connect; I am not a networking expert, but the fact that pinging a device returns "destination host unreachable" seems a little off

I will award the first person to find a successful solution. Seeing that having an ADB USB connection gives a user access to both the mobile device's and host's terminal, there really is no excuse for a connection not to be able to be made between the two.

Update 2:

I have recently had more success in connecting to the ADB as well as receiving successful pings at my school network. Note at this network connects are insecure and the host and mobile devices where on separate subnetworks. Any idea why these conditions would work over my secure network at home that uses only one subnet?

like image 734
Benjamin Brownlee Avatar asked Mar 16 '18 21:03

Benjamin Brownlee


People also ask

How can I connect to Android with adb over TCP?

Steps for connecting the Android with ADB over TCPConnect your android device with a laptop/pc using a USB cable. Then in the android device turn on developer options from settings, and in developer options turn on USB Debugging (PTP/ MTP).

Why adb connect not working?

Failed ADB connections usually have one root cause: bad Android USB drivers that load in place of the right ones. Windows doesn't make it easy to remove the wrong drivers, unfortunately. But before attempting to troubleshoot an ADB connection, first enable USB debugging on your phone if it's not on already.


2 Answers

Try starting from scratch and setup ADB-over-tcp following steps below:

  1. Turn off USB debugging on your device and turn it on again (just to reset).
  2. Kill the ADB server on your PC using adb kill-server
  3. Connect your device to the PC using the USB cable and type adb devices. This will automatically restart the ABD server again.
  4. Enter adb tcpip 5555 on your PC terminal. This will switch the adbd daemon on your device to tcp-ip mode.
  5. Disconnect your device from USB. Now connect your device to the same wireless network as your PC, either the same wi-fi or use your phone as a hotspot.
  6. Determine your phone's ip. You can do this in the wi-fi settings on your phone. If you are using your phone as hotspot, then generally your ip should be 192.168.43.1 (not required but most of the time it's the same).
  7. Connect to ADB via tcp using adb connect <IP>

This should hopefully connect your device to your pc via tcp-ip.

like image 124
riyaz-ali Avatar answered Sep 28 '22 03:09

riyaz-ali


I found a solution that works for me, but I feel it shouldn't necessary and it may not applicable for everybody else with these issues, so its still not quite what I was aiming for.

Anyways, after seeing riyaz-ali suggest what an IP address I should be for using a mobile hotstop through a phone, I realized any network complications would be solved if I was the network, so I connected my mobile device to the mobile hotspot on my laptop.

Instant ping responses and immediate ADB connection with the popularly suggested commands.

like image 38
Benjamin Brownlee Avatar answered Sep 28 '22 04:09

Benjamin Brownlee