Run adb in Termux without root permissions!

Overview

termux-adb

Run adb in Termux without root permissions!

Description

This is a launcher for adb which enables debugging of one Android device from another via USB cable. It should work with any USB-C male-to-male cable or the corresponding OTG adapter + cable in case of micro USB.

Installation

  • install Termux from F-Droid
  • install Termux:API from F-Droid
  • in Termux:
$ pkg install termux-api android-tools
  • download binaries for your target architecture from Releases
  • copy termux-adb and libadbhooks.so to some path accessible from Termux session (both files must be in the same directory)

Usage

First start adb server using the special launcher

$ ./termux-adb

Then you can run any adb commands directly, e.g.

$ adb devices

Build instructions

(You can check the Dockerfile for minimal toolchain setup)

Requirements: linux environment with working gcc and rustup plus all of the following:

  1. download Android NDK r22b (I wasn't able to make it work with any newer NDK version)
  2. add linker paths to ~/.cargo/config
[target.armv7-linux-androideabi]
linker = "/abs/path/to/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang"

[target.aarch64-linux-android]
linker = "/abs/path/to/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
  1. install cross-compilation targets (this will also install rust nightly for the c_variadic feature)
$ ./rustup-install-targets.sh
  1. build individual components (termux-adb, adb-hooks, termux-fastboot) using ./android-build.sh
  2. alternatively run ./make-release.sh to build and package all of them at once

There are also scripts for

  • creating a docker toolchain image (./docker-make-toolchain.sh)
  • and building the project inside it (./docker-make-release.sh)

How it actually works

Termux has the android-tools package which contains adb (and fastboot) but it normally works on rooted devices only. This is mainly due to filesystem permissions required by adb when enumerating USB devices (traversing /dev/bus/usb/*).

There is, however, Android API exposed by termux-usb utility which gives you a raw file descriptor of any connected USB device after manual approval by the user.

Of course, adb by itself doesn't know anything about termux-usb nor it can take raw file descriptors from command-line or environment. If it cannot access /dev/bus/usb, it just won't detect any connected devices. This is where termux-adb comes in.

To avoid the need for patching adb source code, termux-adb uses LD_PRELOAD to inject a dynamic library that hooks a couple of libc functions and emulates access to /dev/bus/usb as if the corresponding directory structure was accessible. There it will set up a virtual character device backed by the file descriptor obtained from termux-usb.

Because adb forks itself and runs in the background when you run it for the first time, it means it can scan for newly connected USB devices continuously. In order to emulate this behavior, termux-adb also runs in the background, polls termux-usb periodically and sends any discovered file descriptors via a Unix Domain Socket connection to the injected library running along adb server. That way the virtual directory tree is kept up to date which is reflected in the output of adb devices.

Currently, termux-adb is limited to one USB device at a time but this can be improved in the future.

You might also like...
Workflows make it easy to browse, search, execute and share commands (or a series of commands)--without needing to leave your terminal.
Workflows make it easy to browse, search, execute and share commands (or a series of commands)--without needing to leave your terminal.

Workflows The repo for all public Workflows that appear within Warp and within commands.dev. To learn how to create local or repository workflows, see

a FREE and MODERN split-screen tetris game WITHOUT ADS
a FREE and MODERN split-screen tetris game WITHOUT ADS

tetr:: A ✨ modern ✨ Tetris game made in OpenGL and Rust Gameplay tetr:: is an implementaion of modern Tetris, and essentially a clone of tetr.io. This

Remote-Archive is a utility for exploring remote archive files without downloading the entire contents of the archive.

[WIP] REMOTE-ARCHIVE Remote-Archive is a utility for exploring remote archive files without downloading the entire contents of the archive. The idea b

Cargo subcommand for running cargo without dev-dependencies.

cargo-no-dev-deps Cargo subcommand for running cargo without dev-dependencies. This is an extraction of the --no-dev-deps flag of cargo-hack to be use

Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.
Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.

What is Tight Model Format The main goal of the tmf project is to provide a way to save 3D game assets compressed in such a way, that there are no not

A Python package written in Rust for email verification without sending any emails.

PyRustify PyRustify is a Python package written in Rust that verifies the email addresses. Features Feature Description Syntax validation Checks if th

Unborrowed Rust Compiler (rustc without a borrowchecker)

ubrustc: Unborrowed rustc This is rustc with the borrow checker disabled. I wrote it in like, 30 minutes because this tweet made me laugh. Example //

A crate to help you copy things into raw buffers without invoking spooky action at a distance (undefined behavior).

🗜 presser Utilities to help make copying data around into raw, possibly-uninitialized buffers easier and safer. presser can help you when copying dat

Tool to allow parsing large JSON files without laoding into memory
Tool to allow parsing large JSON files without laoding into memory

Tool to allow parsing large JSON files without laoding into memory. Developed in Rust with adapters in other programming langauges for easy adoption

Comments
  • CANNOT LINK EXECUTABLE

    CANNOT LINK EXECUTABLE

    Attempting to load termux-adb-v0.1.0-aarch64 and getting: CANNOT LINK EXECUTABLE "adb": cannot locate symbol "libusb_unref_device" referenced by "/data/data/com.termux/files/home/source/termux-adb/termux-adb-v0.1.0-aarch64/libadbhooks.so"...

    termux-api/stable,now 0.57 aarch64 [installed,automatic] Termux API commands (install also the Termux:API app)

    libusb/stable,now 1.0.26-1 aarch64 [installed,automatic] A C library that provides generic access to USB devices

    android-tools/stable 31.0.3p1-6 aarch64 Android platform tools

    $ which adb /data/data/com.termux/files/usr/bin/adb

    $ /data/data/com.termux/files/usr/bin/adb version Android Debug Bridge version 1.0.41 Version [email protected] Installed as /data/data/com.termux/files/usr/bin/adb

    Thank you for having given such quick responses!

    Any thoughts?

    opened by imnisp 9
  • [Request] Consider reaching out to Termux team to add project to repository, getting more official support.

    [Request] Consider reaching out to Termux team to add project to repository, getting more official support.

    Have you considered reaching out to the Termux team to get this project added to their repository? I'd like to see more official support because I'm worried it maybe lost/forgotten and go unmaintained at some point. This is allowing me to access another android with my Z Fold 4 over USB without needing root on the Z Fold. I used it earlier to grab logs and some files from a LG v30 that was running a custom rom after it hard crashed for debugging. This is pretty dang awesome, I can't thank you enough for writting this code and getting android-tools working over USB on Termux.

    opened by ShapeShifter499 2
  • Adb server cannot start

    Adb server cannot start

    How to fix air? Please help

    ~ $ ./termux-adb cannot connect to daemon at tcp:5037: Connection refused error: adb server didn't start, check the log: /data/data/com.termux/files/usr/tmp/adb.10233.log

    opened by NHdut 24
Releases(v0.2.0)
Owner
null
Wrapper over MMTk to simplify integration with runtimes: thread management system, object header, root scanning

vmkit A library which provides bunch of building blocks to make a VM in Rust. Feautures MMTK integration out of the box Thread management provided by

null 3 Aug 31, 2024
🕺 Run React code snippets/components from your command-line without config

Run React code snippets/components from your command-line without config.

Eliaz Bobadilla 11 Dec 30, 2022
Padding/aligning values without heap allocation

zero-copy-pads Padding/aligning values without heap allocation. Cargo Features std (default feature): Disable #![no_std]. Enable features that require

Khải 5 Nov 29, 2021
fail CI on rustc and clippy warnings without breakage

A crate + github actions template that fails CI on rustc and clippy warnings without breakage.

Lucas Kent 1 Jan 2, 2022
A mini paste bin and url shortener written in rust without databases.

pb Build $ cargo build --release Environment Variables PB_DATA: /some/path (Default: ./pb_data) PB_SITE: Url of your site. (Default: http://localhost:

Edward P 5 Jul 26, 2022
a Rust library implementing safe, lightweight context switches, without relying on kernel services

libfringe libfringe is a library implementing safe, lightweight context switches, without relying on kernel services. It can be used in hosted environ

edef 473 Dec 28, 2022
A simple program that provides DBus interface to control display temperature and brightness under wayland without flickering

wl-gammarelay-rs Like wl-gammarelay, but written in rust, runs on a single thread, has three times less SLOC and uses DBus (for simplicity). Dbus inte

Max Verevkin 33 Nov 23, 2022
Donate To Charity (A.K.A. Public Goods) Without Lossing Anything

Donate To Charity (A.K.A. Public Goods) Without Lossing Anything

Gajesh Naik 10 Mar 3, 2022
Workflows make it easy to browse, search, execute and share commands (or a series of commands)--without needing to leave your terminal.

Workflows The repo for all public Workflows that appear within Warp and within commands.dev. To learn how to create local or repository workflows, see

Warp 369 Jan 2, 2023
A library for loading and executing PE (Portable Executable) from memory without ever touching the disk

memexec A library for loading and executing PE (Portable Executable) from memory without ever touching the disk This is my own version for specific pr

FssAy 5 Aug 27, 2022