Skip to content

Java/Kotlin library for programmatic access to ADB services, supporting various host environments and ADB Wi-Fi pairing introduced in Android 12. More details in the wiki.

Notifications You must be signed in to change notification settings

DevOculus-Meta-Quest/AdbLib-Google-PlatformTools

Repository files navigation

adblib - Advanced ADB Library

AdbLib Logo

adblib is a powerful Java/Kotlin library that enables programmatic access to ADB services via a socket channel. This library provides functionalities that can be invoked from the adb shell command, making it highly useful for various host environments, from simple command-line applications to complex desktop applications like Android Studio and IntelliJ IDEA.

Quick Links

Overview

adblib is part of the platform tools source code used to build Android Studio or the IntelliJ IDEA IDE. You can find it in the AOSP repository. The goal of this repository is to enable building adblib without cloning the entire platform repository, using non-local dependencies usually shipped with the platform tools.

For more detailed information, read the README.origin.md.

Features

  • Service Invocation
  • Customizable Environments
  • Inversion of Control
  • Asynchronous APIs
  • Performance Optimization
  • Logging
  • Metrics (TBD)
  • Cross-Platform Support
  • Comprehensive Error Handling
  • ADB Wi-Fi Pairing

For a detailed list of features, visit the Features page in our wiki.

Installation

For detailed installation instructions, including building with Bazel, Gradle, and using JitPack, visit our Installation Guide.

Usage

Example: Tracking Devices

This example demonstrates how to use adblib to track all new devices connected through ADB, similar to adb track-devices:

import com.android.adblib.AdbSession
import com.android.adblib.AdbSessionHost
import com.android.adblib.trackDevices
import kotlinx.coroutines.runBlocking

fun main(args: Array<String>) {
    val host = AdbSessionHost()
    val session = AdbSession.create(host)
    val devicesFlow = session.trackDevices()
    runBlocking {
        devicesFlow.collect { deviceList ->
            println("### Change in state ###")
            deviceList.devices.forEach { device ->
                println("${device.model}: ${device.serialNumber}: ${device.deviceState}")
            }
        }
    }
}

Output while connecting and disconnecting a Pixel 8 phone:

### Change in state ###
### Change in state ###
Pixel_8: XXXXXXXXXXXXXX: ONLINE
### Change in state ###
Pixel_8: XXXXXXXXXXXXXX: OFFLINE
### Change in state ###

For more examples, visit our Usage Examples page.

Integrations

Android Studio

To integrate adblib with Android Studio, follow the instructions in our Android Studio Integration Guide.

Visual Studio

To integrate adblib with Visual Studio, follow the instructions in our Visual Studio Integration Guide.

Metrics

adblib allows consumers to collect various performance and reliability metrics of the underlying ADB host. This feature is currently not implemented but will be available in future releases.

Contribution

We welcome contributions! Please fork this repository and submit pull requests. If you encounter issues, feel free to open an issue or contact the maintainers.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Why We Created This Repository

We created this repository to provide a standalone version of adblib that can be used independently of the platform tools repository. This allows developers to integrate ADB functionalities into their applications more easily without the need to clone and build the entire platform repository. Our goal is to make it simpler and more convenient to access ADB services programmatically in various development environments.

For more details, visit the Why We Created This Repository page.

Disclaimer

I am not the owner nor the maintainer of the source code of adblib. I created this repository to use the library outside of the platform tools, as there is currently no standalone release.

If you have trouble building the library, please open an issue in this repository. For other inquiries, contact the original OWNERS or report a bug in the official bug tracker.

Repository

You can find the repository for this project at https://github.com/DevOculus-Meta-Quest/AdbLib-Google-PlatformTools.

About

Java/Kotlin library for programmatic access to ADB services, supporting various host environments and ADB Wi-Fi pairing introduced in Android 12. More details in the wiki.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published