#ndk #binder #env

sys binder_ndk_sys

Rust bindings for Android's Binder IPC mechanism

6 releases

0.2.0 Aug 10, 2023
0.1.4 Aug 10, 2023

#1450 in Development tools

Download history 31/week @ 2023-10-21 22/week @ 2023-10-28 13/week @ 2023-11-04 54/week @ 2023-11-11 45/week @ 2023-11-18 56/week @ 2023-11-25 15/week @ 2023-12-02 39/week @ 2023-12-09 25/week @ 2023-12-16 42/week @ 2023-12-23 30/week @ 2023-12-30 41/week @ 2024-01-06 30/week @ 2024-01-13 19/week @ 2024-01-20 47/week @ 2024-01-27 25/week @ 2024-02-03

126 downloads per month
Used in 2 crates (via binder_ndk)


100 lines


The stub libbinder_ndk.so in ndk's sysroot hides some apis, so that we cannot link our libbiner_rs to it. However, we can rebuild a stub so to make linker happy. The stub source is generated from symbols.txt, whose contents are extracted from prebuilt libbinder_ndk.so from aosp-mainline.

The libbinder_ndk.so is introduced in api-29, you need to compile it with specified target api level. The compilation won't failed if api is lower than 29, because we build the dynamic library on ourselves.

We use ndk-build to build the stub so, ANDROID_NDK_HOME must be set in your env !

sys/src/include_* from platform/frameworks/native/libs/binder/ndk


  1. Build

    cargo ndk -t arm64-v8a --platform=29 --bindgen build
  2. Push file to phone

    adb push target/aarch64-linux-android/debug/binder-example /data/local/tmp
  3. Run 2 adb shell

    Run server:

    adb shell
    su -c /data/local/tmp/binder-example server

    Run client:

    adb shell
    su -c /data/local/tmp/binder-example client


  1. Build

    cargo ndk -t arm64-v8a --platform=29 --bindgen build
  2. Push files to phone

    adb push target/aarch64-linux-android/debug/binder-tests /data/local/tmp
  3. Build unittest binary

    cargo ndk -t arm64-v8a --platform=29 --bindgen test --bin binder-tests --no-run
  4. Push files to phone

    adb push target/aarch64-linux-android/debug/deps/binder_tests-acf830ec15b8864e /data/local/tmp
  5. Run test

    adb shell
    cd /data/local/tmp/ && su -c ./binder_tests-acf830ec15b8864e

    if you see error like this

    CANNOT LINK EXECUTABLE "/data/local/tmp/binder_tests-acf830ec15b8864e": cannot locate symbol "AIBinder_DeathRecipient_setOnUnlinked" referenced by "/data/local/tmp/binder_tests-acf830ec15b8864e"...

    This is because your android version is too low, the source is from android-mainline. You can try in avd, with Android U


Generated Rust bindings to libbinder_ndk

No runtime deps

~37K SLoC