Use Secure ADB for Remote Android Device Debugging

Keith Szot

November 07, 2019

It’s Thanksgiving Day, you get a call that your POS app at the flagship store keeps crashing right before they are about to open up to the Black Friday throng. You are in the middle of your company’s biggest flash sale ever and your kiosk keeps crashing. The horror!

We’ve all been there, where that one device doesn’t operate correctly out of your fleet of thousands and no one can figure out why. Whether you see the random one-off in Crashlytics, or the regional VP is calling you at 6 am; what can you do short of hopping on a plane with your dev laptop and USB cable getting there many hours later and plenty of downtime in between?

ADB is that one trusted, steady friend who’s always got your back. Android Debug Bridge helps developers squash bugs in their applications. It also installs apps outside of Play Store, accesses hidden features, and brings up Unix shell to issue commands directly to the device. That’s an all-rounder!

Esper offers a means to use adb remotely and debug your devices to make your life that much easier. Let’s do it together! This blog will show you how to debug devices on the Esper platform using adb remotely and securely.

Access Remote Viewer And Control, Get Bug Logs

Before we get into adb, Esper has a few other tools to apply. First, go to Devices in the Esper Console, find an active device and click Details > to access the available commands:

This brings up all the information and actions specific to that device:

With Remote viewer you can see what’s going on and determine if it is a user error or a training issue. Remote viewer gives you a live view of the device’s screen, accounting for network delays of course.

You’ll notice that you have an option to do Remote Control by going to full screen. It is only available on Android devices where the Esper Agent has been signed by the device maker (which we are happy to get done for you for your devices) or on Esper Enhanced Android devices. 

But Remote viewer works pretty much on any supported Android device – on stock Android devices a local user will need to confirm remote viewing, but with Esper Enhanced Android devices user interaction is not required.

You can also capture bug report logs from the device that can help you figure it out remotely using Esper:

Good software development practice is trying to locally reproduce the bug. You may have the same device sitting in your hardware test lab, but you’ve moved on months ago from the field device’s provisioning settings – how do you set it up for precise reproduction? That’s where Esper Device Templates come in. With proper Device Template naming practice you can easily grab the old template and provision the device to the same condition as the device deployed in the field and give it a go.

But of course you can’t reproduce the bug in the office! That’s how it goes. Guess it’s time to buy that ticket to the red eye to Miami. But wait, with Esper you have one more option available to you – secure remote ADB.

Set up adb to Remotely Debug Deployed Devices

With Esper you can initiate a secure remote ADB session with any Esper provisioned Android device. If you are running Esper Enhanced Android you get zero-touch secure remote adb. We will use a Kingfisher smartphone running Android 8.1 for the example.

In addition to access to the Esper Console you’ll need to install the Esper CLI and configured it to your endpoint. Installation instructions here.

Go to Devices, select the device you want to initiate an ADB session, then click on the Actions tab which includes a switch for turning on secure remote ADB.

To start you simply need to switch ADB to on:

To ensure secure remote ADB, sessions are limited to 30 minutes. Of course a new session can be established if more than 30 minutes is needed.

For stock Android devices, another step needs to be executed locally on the device. The device port has to be opened for the Esper Agent running on the device to set up the secure connection using the Esper Platform. But instead of sending a developer out, you can have a local field resource perform this action on behalf of the development team keeping them in the office. Once the stock Android device is connected via USB to a PC running some form of Terminal with ADB (approving the permissions asked for on the device), run this command to enable ADB over tcpip:

adb tcpip 5555

Here’s the return status you will see:
restarting in TCP mode port: 5555

Note the above command is unnecessary for devices running Esper Enhanced Android. 

Now from the command line you use the espercli command secureadb giving it the device ID for your debugging target. In this case the device ID is ESP-DMO-AZ40:

espercli secureadb connect -d ESP-DMO-AZ40 

You’ll get this message right away…:
Initiating Remote ADB Session. This may take a few seconds…

Wait for it…and there you go! Note the endpoint address shown below will likely be different for your session:

Secure ADB Client
Please connect ADB client to the following endpoint: : 51556
If adb-tools is installed, please run the command below:
Adb connect
Press Ctrl+C to quit!

Now switch to a new terminal window and start up your ADB connection using the IP address supplied by the secureadb command from the espercli:

adb connect

You’ll get this message back:
Connected to

You now have a secure remote ADB session for that device. Now all your ADB tools are available to you, like logcat:

To exit your ADB session simply enter ^c into the terminal window.

And that’s it!

Give it a try and start remote debugging your deployed apps for your purpose-built fleet using Esper. You can start by logging into your Esper platform or signing up for a FREE trial. 

To reach the Esper team, just email to