Connecting To ADB Over The Internet

We used to have a physical server in our studio to run our Jenkins continuous integration for our Android projects, but after several machines gave up in quick succession I decided it would be cheaper and less time consuming to set one up in the cloud (we chose Digital Ocean as we already have a few virtual servers there). This means we don't have to worry about hardware failures, our studio internet connection, or backing up (digital ocean can do that for you). One less thing to worry about!

However, this presented us with a challenge... We like to run some of our tests (connectedAndroidTest) on real devices, and you can't really plug a usb hub into a 'cloud'.

Solving The Problem

I solved this problem with a Raspberry Pi and an ssh tunnel.


Adb has several parts: a client, a server, and the bit that runs on the Android device.

Essentially, the adb client runs when you type 'adb' on the command line, this then connects to the adb daemon (over a port). The adb daemon runs in the background and is the bit that connects to the devices over usb.

Tunnel Pi

We now have a Pi in our studio that the Android devices are plugged into. The adb daemon runs on this Pi.

Whenever Jenkins wants to use the devices, it opens an ssh tunnel to the Pi, forwarding a port, so Jenkins' adb client can connect to the Pis' adb daemon. Once this port has been forwarded, adb works as normal. It's actually quite simple!


Your local internet connection. It's gotta be fairly good. For example, it works flawlessly on a 30mb connection, but sometimes timed out over a very busy 6mb connection.

Adb isn't available to download for the Pi, so you have to compile it yourself. You have to make sure the adb client and adb daemon are the same versions, otherwise they refuse to talk to each other.

How Do I Set This Up?

For detailed step by step instructions, including compiling adb on the Pi and what to run in your Jenkins job, I've written it up as a Gist...