Some notes from my successes and failures.
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.
- Make sure you Android device and computer are on the same wifi.
- Make sure you've updated Android
platform-tools
to the latest. - If doing from a clean start; revoke all USB Debugging authorisations from Android device developer options.
- Close Android Studio (logcat keeps trying to connect to the device, I feel like this interferes sometimes)
- Plug your device into your computer
- Authorise the computer on the device
- Check the device status:
adb devices
. - Disconnect from all TCP/IP devices:
adb disconnect
- Change to use TCP IP:
adb tcpip 5555
- Connect using TCP IP:
adb connect <device-ip>:5555
- Unplug device
- Check the device status:
adb devices
.
* 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.
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
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 (likeshell
) 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.