Skip to content

Instantly share code, notes, and snippets.

@peter-tackage
Last active October 10, 2023 20:09
Show Gist options
  • Save peter-tackage/ab337d76d47624de45be9327a0c8dedc to your computer and use it in GitHub Desktop.
Save peter-tackage/ab337d76d47624de45be9327a0c8dedc to your computer and use it in GitHub Desktop.

Android ADB over wifi

Some notes from my successes and failures.

Definitions

From the official docs

It is a client-server program that includes three components:

  • A client, which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command.

  • A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.

  • A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.

Preparation

  1. Make sure you Android device and computer are on the same wifi.
  2. Make sure you've updated Android platform-tools to the latest.
  3. If doing from a clean start; revoke all USB Debugging authorisations from Android device developer options.
  4. Close Android Studio (logcat keeps trying to connect to the device, I feel like this interferes sometimes)

Sequence

  1. Plug your device into your computer
  2. Authorise the computer on the device
  3. Check the device status: adb devices.
  4. Disconnect from all TCP/IP devices: adb disconnect
  5. Change to use TCP IP: adb tcpip 5555
  6. Connect using TCP IP: adb connect <device-ip>:5555
  7. Unplug device
  8. Check the device status: adb devices.

Troubleshooting

* failed to start daemon
adb: failed to check server version: cannot connect to daemon

This might mean you need to update your Android platform-tools, or that perhaps you have two installations of the Android SDK resulting in a version mismatch. This can happen when Android Studio is open, and is using its own Android SDK installation to attempt to connect logcat.

Also, there might be another process holding onto the port 5037 used by ADB daemon: find the PID to kill using sudo lsof -i tcp:5037.

error: more than one device/emulator

This is self explanatory, but the client side does know which device daemon to communicate with. This would usually happen when running commands such as adb usb where the client wants to switch the connection mode of a daemon, but there are multiple devices, so it doesn't know what to do.

Reset Commands

Try various combinations of:

  • adb kill-server
  • adb disconnect
  • sudo lsof -i tcp:5037
  • Revoking authorisations on the device
  • Restarting the device
  • Use adb usb to switch back to USB based connections

More generally:

internal debugging:
 start-server             ensure that there is a server running
 kill-server              kill the server if it is running
 reconnect                kick connection from host side to force reconnect
 reconnect device         kick connection from device side to force reconnect
 reconnect offline        reset offline/unauthorized devices to force reconnect
@navid-zamani
Copy link

BEWARE: When you’ve connected over tcpip, and the wifi cuts out, then adb -s "$ip:$port" get-state will NOT show that, until a command (like shell) is issued, or until quite some time has passed. There is no reliable way of detecting that with adb. The only way to trigger it, is to execute a command, have it hand, and Ctrl-C it manually. Making it completely useless for automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment