In this post I’d like to describe you how to set adb over Wifi or Ethernet. As you probably already know, the adb (a.k.a. Android Debug Bridge) is a powerful tool that allows you to shell directly to the emulator or to a connected real device. Indeed, many other actions are available, such as:
- copying files from/to the device
- installing and removing and apps
- managing port forwarding
- making backup and restoring older archives
- partitions synchronization
- seeing the log from the device
- checking for bug report
The architecture of the adb system is quite complex due to the high number of features it has. Basically it is formed by a adb server on the host machine (that is, the PC for instance) and an adb daemon on the target (i.e., on the real device). The former aims at managing the connection to the target through USB or TCP/IP and to proxy and forward the data received from the device to the other components that (likely) are running, such as:
- the command shell,
- the emulator itself,
- the ddms utility or,
- the ddms plugin inside Eclipse
Conversely, on the target, the adb daemon (named adbd) will manage the requests from the host and communicate locally with the native user-space, with the Java user-space and the kernel.
When approaching to the Android development, the usb is frequently used as the default connection in order to upload apks, to debug apps or to check for the Android log. However, setting up the adb over Wifi or Ethernet might be a valid opportunity when:
- your device is not spatially close to the host (pc) therefore is not possible to leverage the usb connection.
- your mini-usb connector (or cable) is broken or for any reason is not working
- you don’t have a free usb port neither a usb hub at hand.
So, how to connect the adb over wifi? The following simple steps are needed in order to achieve that. These commands have been tested on a Ltouch FW Android multi-touch panel, an HMI designed for home and industrial automation projects. However, this procedure can be extended as for any other Android-based device.
- First, make sure you know in advance the ip address of the smartphone/tablet on the network. You can get it through a shell to the device and using the netcfg command. You will get the list of all the network interfaces, like for instance:
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00 eth0 UP 0.0.0.0/0 0x00001003 00:09:c0:ff:ec:48 sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00 wlan0 UP 192.168.1.4/24 0x00001043 08:10:78:51:15:35
The ip address assigned is the one that corresponds to the “UP” network interface (i.e., running), different from localhost (127.0.0.1).
- Now, connect your device to the host pc using the usb cable.
- Verify that the adb server on the host is working and the device is detected by typing the command
adb devices
If a connection between the host and the device is established, the outcome should be:
List of devices attached 0123456789ABCDEF device
Conversely, when no devices are connected, you’ll get only
List of devices attached
- Restart the adb server (on host) and set it in a way that it will accept requests from tcp and in particular from a port (say, 5554). Type:
adb tcpip 5554
- Tell the adb which is the ip address to connect to. The ip provided refers to the one found on the first step.
adb connect 192.168.1.3:5554
- Your adb server on host is working and will connect using tcp. To test whether everything is fine, type
adb devices
and you’ll get the list of connected devices and in particular the ip address and port.
List of devices attached 192.168.1.3:5554 device
Now your adb over wifi is perfectly working!
For more information, take a look at the Google ADB web page.