A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server

Related tags

Kotlin Projects dadb
Overview

dadb

Maven Central

Blog Post: Our First Open-Source Project

A Kotlin/Java library to connect directly to an Android device without an adb binary or an ADB server

dependencies {
  implementation("dev.mobile:dadb:<version>")
}

Example Usage

Connect to emulator-5554 and install apkFile:

Dadb.create("localhost", 5555).use { dadb ->
    dadb.install(apkFile)
}

Note: Connect to the odd adb daemon port (5555), not the even emulator console port (5554)

Discover a Device

Searches localhost ports 5555 through 5683 for a valid adb device:

val dadb = Dadb.discover("localhost")
if (dadb == null) throw RuntimeException("No adb device found")

Install / Uninstall APK

dadb.install(exampleApkFile)
dadb.uninstall("com.example.app")

Push / Pull Files

dadb.push(srcFile, "/data/local/tmp/dst.txt")
dadb.pull(dstFile, "/data/local/tmp/src.txt")

Execute Shell Command

val response = dadb.shell("echo hello")
assert(response.exitCode == 0)
assert(response.output == "hello\n")

License

Copyright (c) 2021 mobile.dev inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Does it work with Android application?

    Does it work with Android application?

    I am using computer with adb installed to update some apps on my nvidia shield. My nvidia shield has network debugging enabled.

    I would like to create an android app that could "send adb commands" to my shield. Can I use your library for this purpose or is it only intended to be used on desktop? Is there any special permission to give to the android application?

    opened by sharpordie 11
  • Use Dadb to connect two Android devices (phone/watch)

    Use Dadb to connect two Android devices (phone/watch)

    Hi, I'm interested in using this library to connect an Android phone to an Android (WearOS) watch, with the Dadb-enabled app running on the phone. ADB over wifi would be enabled on the watch, and I would know the ip address. What I'd hope for is that the phone app makes an adb connection request to the watch's ip address. This would generate a prompt on the watch that the user can accept or reject. If the request is accepted, then the connection is established. This is broadly how I've seen other ADB libraries work.

    But I can't figure out how to accomplish that using Dadb. The only example given is connecting to an emulator. The real power of this library would be to connect two actual Android devices over wifi. Please say if this is possible with the current version of Dadb and, if so, give some brief example code.

    Thanks.

    opened by malbry 11
  • Can port forwarding be done with dadb?

    Can port forwarding be done with dadb?

    Hi, there. I've been enjoying playing with this library. Thank you so much for it!

    I have a need to set up port forwarding, as in adb -s emulator-5554 forward tcp:6100 tcp:7100. I suspect this requires the adb server itself, but I'm still green, figuring out how the protocols work. I've tried my own hand at adding a reboot command, via a simple dadb.open("reboot:"), and that worked. So I toyed with something like that I thought might work for forwarding (e.g. dadb.open("host-serial:5554:forward:tcp:10001;tcp:10001)) based on looking at the ddmlib source for forwarding, but I barely know what I'm doing. Obviously, that didn't work for me. Any advice?

    Thanks again for the great library and any help.

    opened by mrubinsquare 11
  • Adding support for TCP port forwarding

    Adding support for TCP port forwarding

    As requested in issue #1

    Usage (Kotlin):

    dadb.tcpForward(
        hostPort = 7001,
        targetPort = 7001
    ).use {
        // Do operations that depend on port forwarding
    }
    
    opened by dmitry-zaitsev 6
  • dadb.AdbStreamClosed: ADB stream is closed for localId: e2527064

    dadb.AdbStreamClosed: ADB stream is closed for localId: e2527064

    I'm getting the following error when calling dadb.install.

    dadb.AdbStreamClosed: ADB stream is closed for localId: e2527064
    

    It looks like it returns a close command immediately when it receives the abb_execute command.

    When the server receives the message it only returns the close command if it can't read the response for some reason. https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/adb.cpp;drc=867c71e5114e76b4f64e9f38e1be060fd9ba3a26;l=475

    Sending shell commands work fine. Calling the install command through adb on my local machine to the same target host also works fine.

    opened by nassendelft 6
  • adb push failed on Android 8.1 devices

    adb push failed on Android 8.1 devices

    	at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
    	at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
    	at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
    	at okio.OutputStreamSink.write(JvmOkio.kt:56)
    	at okio.AsyncTimeout$sink$1.write(AsyncTimeout.kt:99)
    	at okio.RealBufferedSink.flush(RealBufferedSink.kt:267)
    	at dadb.AdbWriter.write(AdbWriter.kt:92)
    	at dadb.AdbWriter.writeClose(AdbWriter.kt:60)
    	at dadb.AdbStream.close(AdbStream.kt:118)
    	at dadb.AdbStream.nextMessage(AdbStream.kt:109)
    	at dadb.AdbStream.access$nextMessage(AdbStream.kt:24)
    	at dadb.AdbStream$source$1.message(AdbStream.kt:61)
    	at dadb.AdbStream$source$1.read(AdbStream.kt:40)
    	at okio.RealBufferedSource.request(RealBufferedSource.kt:206)
    	at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
    	at okio.RealBufferedSource.readByte(RealBufferedSource.kt:209)
    	at dadb.AdbSyncStream.send(AdbSync.kt:73)
    	at dadb.Dadb$DefaultImpls.push(Dadb.kt:54)
    	at dadb.TestDadb.push(DadbTest.kt:331)
    	at dadb.DadbTest$adbPush_basic$1.invoke(DadbTest.kt:119)
    	at dadb.DadbTest$adbPush_basic$1.invoke(DadbTest.kt:113)
    
    opened by tiann 4
  • [RFC] Support for emulator discovery

    [RFC] Support for emulator discovery

    Not sure if you are taking PRs, or consider this in scope, so no offense taken if you close this.

    Ideally I would use host:devices or host:devices-l to find the available emulator and devices. But I couldn't get that working with Dadb (https://github.com/mobile-dev-inc/dadb/issues/7).

    As a shortcut, I read from the avd process files as described here https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:utp/android-test-plugin-host-retention/src/main/java/com/android/tools/utp/plugins/host/icebox/IceboxConfigUtils.kt?q=8554%20f:android

    Original code in https://github.com/yschimke/emulator-tools/commit/96374554160a8707315001796d16f3f8c7f1d25b

    opened by yschimke 4
  • Subclass the shell packets by STDOUT/STDIN/ERR

    Subclass the shell packets by STDOUT/STDIN/ERR

    Making the packets an explicit class type makes it easier to use a when statement and handle the use cases. Using an int type means that a consumer would have to use an else statement, even though the ID types have already been checked.

    opened by SalvatoreT 3
  • docs: update instructions to build the project

    docs: update instructions to build the project

    also updates compileJava tasks with targetCompatibility of 1.8 we do not have any compileJava today, but tomorrow even if we add any annotation-based libraries, a compileJava step will get added, and kotlin and java both should specify the same JVM target

    Signed-off-by: Arnav Gupta [email protected]

    opened by championswimmer 2
  • Issue while discovering local device

    Issue while discovering local device

    I am using dadb and it was not able to discover local device,

    I am using following code to discover locally connected device val dadb = Dadb.discover("localhost") if (dadb == null) throw RuntimeException("No adb device found")

    I ran into following error java.lang.RuntimeException: No adb device found

    opened by sunnyg522 2
  • [Discussion] KMP support

    [Discussion] KMP support

    I'm trying to use a combination of dadb and grpc to the emulator to implement some useful functions when using emulators.

    This led me to a couple of questions

    1. Have you considered Kotlin multiplatform support? You are already using Okio, which is KMP enabled and there is code for KMP Certificate handling code in github.com/cashapp/certifikit. Generally seems like a incremental change that could unlock a lot of other cases.
    2. Have you considered supporting gRPC in Dadb also?

    I have a working implementation of gRPC using Square's Wire project (again KMP native)

    https://github.com/yschimke/emulator-tools/blob/main/src/jvmMain/kotlin/ee/schimke/emulatortools/Main.kt#L41-L48

    again, please close if this it undesired or out of scope and I'll maintain the bits I need separately.

    opened by yschimke 2
  • Discover returns an error

    Discover returns an error

    Hi guys,

    I'm Victor, and I'm trying to run the library in a poc application to know how to use it. But the first method that I'm trying is "discover", but it returning me a FileNotFoundException

    I'm doing:

    fun discover(){
            try {
                val result = Dadb.discover("localhost")
                binding.tvcommandline.text = "" + result.toString()
            }catch (ex: java.lang.RuntimeException){
                binding.tvcommandline.text = "Failed to discover emulator. No adb device found"
                ex.printStackTrace()
            }
        }
    
    

    The error is:

    Caused by: java.io.FileNotFoundException: .android/adbkey: open failed: ENOENT (No such file or directory)

    Some advice?

    I'm testing on a Samsung S20 Ultra with Android 12 and connected via USB.

    Thank you

    opened by victorjaviermartin 10
  • How to pair Android 11+ devices?

    How to pair Android 11+ devices?

    Is the pair command supported by Dadb? If not, it would be great to add this feature.

    https://developer.android.com/studio/command-line/adb#connect-to-a-device-over-wi-fi-android-11+

    opened by sharpordie 9
  • Discover and create are hanging endlessly

    Discover and create are hanging endlessly

    The discover and create functions are hanging as long as the allow button has not been clicked. Internally this is the open function that blocks endlessly. Is this the desired behavior? If so, why?

    val dadb = Dadb.discover("192.168.1.62")
    

    screen

    It would be great to throw timeout exception after x seconds. Or throwing something like AuthorizationRequiredException or FailedAuthenticationException would be even better.

    It's trivial with the official binary, you just have to check the connect output.

    adb connect 192.168.1.62
    * daemon not running; starting now at tcp:5037
    * daemon started successfully
    failed to authenticate to 192.168.1.62:5555
    
    enhancement 
    opened by sharpordie 3
Owner
mobile.dev
mobile.dev
Template for building CLI tool in Kotlin and producing native binary

Kotlin command-line native tool template This template allows you to quickly build command-line tool using Kotlin , Clikt and build a native binary fo

Ryszard Grodzicki 10 Dec 31, 2022
An AutoValue extension that generates binary and source compatible equivalent Kotlin data classes of AutoValue models.

AutoValue Kotlin auto-value-kotlin (AVK) is an AutoValue extension that generates binary-and-source-compatible, equivalent Kotlin data classes. This i

Slack 19 Aug 5, 2022
Jambeez-server - Jambeez server with kotlin

jambeez-server How to start Start your own server with: docker pull ghcr.io/jamb

null 5 Apr 2, 2022
Allowing server admins to backdoor their own server!

DiscordBackdoorBot Allowing server admins to backdoor their own server! What does Discord Backdoor Bot do? Discord Backdoor bot allows the bot owner t

Awesomemoder316 1 Jun 8, 2022
A simple Kotlin class to use to connect to a MongoDB collection.

mongodb-kotlin A simple Kotlin class to use to connect to a MongoDB collection. Once you have created a MongoDB project, choose Build a Database: Next

null 2 Oct 23, 2022
The behavior of Couchbase Lite C when attempting to connect to a Sync Gateway

This demo demonstrates the behavior of Couchbase Lite C when attempting to connect to a Sync Gateway, while the process has various numbers of file de

Gabriel Terwesten 0 Nov 29, 2021
Kafka Connect connector for CØSMOS based blockchains.

CØSMOS Kafka Connector Kafka Connect connector for CØSMOS based blockchains. Purpose The Kafka Connect CØSMOS Source connector is a Kafka connector us

OKP4 – Open Knowledge Protocol For 6 Nov 23, 2022
Kafka Connect JSLT Single Message Transform

This is an implementation of the Kafka Connect SMT interface to offer transformation capabilities using the Schibsted JSLT library.

willhaben 2 May 25, 2022
Therapeutic is a platform to help easily connect patients or generally anyone struggling to get through tough times with motivating content and professional therapists.

Therapeutic Apk - https://github.com/develNerd/Therapeutic/blob/main/androidApp/release/androidApp-release6.apk Therapeutic is a Kotlin Mobile Multipl

Isaac Akakpo 1 Nov 23, 2022
🌱 A test implementation of a Minecraft server using RESTful API taking advantage of the interoperability between Kotlin and Java.

?? Norin A test implementation of a Minecraft server using RESTful API taking advantage of the interoperability between Kotlin and Java. This project

Gabriel 1 Jan 4, 2022
Mock up social media android application created to interact with a backend Java server using GraphQL.

The Community Board Project Authorship: author: dnglokpor date: may 2022 Project Summary: The Community Board Project consists of a Java Spring Boot b

Delwys Glokpor 1 May 17, 2022
GraphQL Jetpack - A collection of packages for easily writing Java GraphQL server implementations

GraphQL Jetpack A collection of packages for easily writing Java GraphQL server

Ryan Yang 18 Dec 2, 2022
An Android Image compress library, reduce's the size of the image by 90% without losing any of its pixels.

Image Compressor An Android image compress library, image compressor, is small and effective. With very little or no image quality degradation, a comp

Vinod Baste 11 Dec 23, 2022
Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

mohsen 21 Dec 3, 2022
A multifunctional Android RAT with GUI based Web Panel without port forwarding.

AIRAVAT A multifunctional Android RAT with GUI based Web Panel without port forwarding. Features Read all the files of Internal Storage Download Any M

The One And Only 336 Dec 27, 2022
Quickly rotate screen on Android devices without second thought

Useful uitlity for ONYX BOOX Eink devices. It provides several quick actions to be added in top system panel

Daniel Kao 21 Jan 3, 2023
A simple textfield for adding quick notes without ads.

Simple Notes A simple textfield for adding quick notes. Need to take a quick note of something to buy, an address, or a startup idea? Then this is the

Simple Mobile Tools 670 Dec 31, 2022
Easy app for managing your files without ads, respecting your privacy & security

Simple File Manager Can also be used for browsing root files and SD card content. You can easily rename, copy, move, delete and share anything you wis

Simple Mobile Tools 1.2k Dec 29, 2022