We are mobile engineers who have spent our careers building mobile applications at industry-leading companies like Uber, and we’ve made it our mission to solve the hard problems in mobile development. Along the way, we’ll be building novel technology and will continue to share our learnings with the community.
Today, we’re excited to announce our first open-source project, dadb!
The dadb
(“direct-adb”) library follows the Unix philosophy — “Do one thing and do it well”. So with that in mind, let’s dive into dadb
.
dadb
A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server
Why we built dadb
At mobile.dev, we run custom Android emulators at scale in the cloud. Reliable communication with these emulators is critical to the stability of our infrastructure.
Other available solutions require either calling out to the adb
CLI, or require an already-running ADB server as a prerequisite.
This is akin to shelling out to a curl
binary to programmatically execute HTTP requests, or having to ensure a running daemon process in your container before using an HTTP client.
We built dadb
to remove all dependencies on external binaries and processes enabling a simplified architecture and more robust communication with our Android emulators.
When should you use dadb?
Check out dadb
if you’ve ever written code that looks like this:
Runtime.getRuntime().exec(“adb install “ + apkFile)
Or maybe you have…
All of the patterns above rely on a separate adb binary for device communication.
If you’re writing any logic that requires communication with Android devices over adb
, you should consider using dadb
.
dadb Benefits
dadb
is a pure JVM library that allows you to communicate directly with Android devices without relying on an adb binary.
Why does this matter?
- Avoids parsing shell command output
- Avoids spawning separate shell processes
- Avoids having to manage a separate ADB server background process
- Avoids having to run setup commands like “adb connect …”
- Avoids internal threading to manage device connections
How does it work?
dadb
circumvents the ADB server, and instead, the library speaks directly to the ADB daemon port on the device.
This is made possible by the library’s pure Kotlin implementation of the adb protocol:
class AdbMessage(
val command: Int,
val arg0: Int,
val arg1: Int,
val payloadLength: Int,
val checksum: Int,
val magic: Int,
val payload: ByteArray
)
Check out dadb’s connection logic for an example of how this class is used.
From a device’s perspective, dadb
commands are indistinguishable from those coming from an ADB Server.
Usage
Connect to an emulator running at “localhost:5555” and install an apk:
Dadb.create("localhost", 5555).use { dadb ->
dadb.install(apkFile)
}
Check out the README for more detailed instructions.
Going Forward
We’ve been using dadb
in production for months now with no issues, but if you run into any bugs, please open an issue. And, of course, we welcome pull requests!
We also know that dadb
only supports a subset of adb functionality today, so feel free to open an issue if you’d like us to prioritize a specific feature.
We’re just getting started here at mobile.dev. If this sort of work interests you, we’re hiring! https://angel.co/company/mobile-dev-inc