Skip to content

Instantly share code, notes, and snippets.

Last active Mar 22, 2019
What would you like to do?
Connect to adb over a network. Useful for running jenkins in 'the cloud', but testing on real devices locally.

Connect your devices to a pi that has been configured like below.

Pi Setup

Download raspbian etc, go through normal setup.

Setup networking

This will let you find your pi locally using it's name, e.g. ping davepi.local

sudo apt-get update
sudo apt-get install avahi-daemon

Set a static ip

sudo nano /etc/network/interfaces

Then do something clever in here. Aftwards, make sure your ports are forwarded in your router, so the pi can be seen from the outside world.

Compile adb

Because you can't download adb for the pi.

Your development server adb will need to be the same version as the pi adb.

sudo apt-get install git build-essential libncurses5-dev libssl-dev
mkdir aosp
cd aosp
git clone system/core
git clone external/zlib

You might need to checkout a speific brach, tag, or commit here. See this page for branches / tags

cd system/core/adb
wget -O Makefile
make adb
sudo cp adb /usr/local/bin/

Set correct permissions on adb

sudo chown root:mylovelyusername /usr/local/bin/adb
sudo chmod 4550 /usr/local/bin/adb

SSH Login

mkdir ~/.ssh
nano ~/.ssh/authorized_keys

Run cat ~/.ssh/ on your development machine / ci server / who ever will be connecting to the pi and copy output into the open file

# Kill and local adb
adb kill-server
# Forward adb port
ssh -f -L 5037:localhost:5037 -N
# Make sure remote adb server is running, and wait for it to start
ssh "adb start-server"
# List the devices, just for fun!
adb devices
# Uninstall your app
adb devices | tail -n +2 | awk '{print $1}' | xargs -I {} adb -s {} uninstall
# Run the tests, but still exit with success so jenkins carries on
./gradlew connectedAndroidTest lintDebug | true
# Grab the exit code of the tests, so we can fail the build later if we need to
# Close the ssh tunnel
ps aux | grep "ssh -f" | grep "5037:" | awk '{print $2}' | xargs kill
# Fail the build, if the tests failed
(exit $MY_EXIT)
# Taken from this lovely post
SRCS+= adb.c
SRCS+= adb_client.c
SRCS+= commandline.c
SRCS+= console.c
SRCS+= file_sync_client.c
SRCS+= fdevent.c
SRCS+= get_my_path_linux.c
SRCS+= services.c
SRCS+= sockets.c
SRCS+= transport.c
SRCS+= transport_local.c
SRCS+= transport_usb.c
SRCS+= usb_linux.c
SRCS+= usb_vendors.c
SRCS+= adb_auth_host.c
VPATH+= ../libcutils
SRCS+= socket_inaddr_any_server.c
SRCS+= socket_local_client.c
SRCS+= socket_local_server.c
SRCS+= socket_loopback_client.c
SRCS+= socket_loopback_server.c
SRCS+= socket_network_client.c
SRCS+= load_file.c
VPATH+= ../libzipfile
SRCS+= centraldir.c
SRCS+= zipfile.c
VPATH+= ../../../external/zlib/src
SRCS+= adler32.c
SRCS+= compress.c
SRCS+= crc32.c
SRCS+= deflate.c
SRCS+= infback.c
SRCS+= inffast.c
SRCS+= inflate.c
SRCS+= inftrees.c
SRCS+= trees.c
SRCS+= uncompr.c
SRCS+= zutil.c
CPPFLAGS+= -I../include
CPPFLAGS+= -I../../../external/zlib
CFLAGS+= -O2 -g -Wall -Wno-unused-parameter
#LDFLAGS= -static
LIBS= -lrt -lpthread -lcrypto -lssl
OBJS= $(SRCS:.c=.o)
all: adb
adb: $(OBJS)
$(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
rm -rf $(OBJS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment