Skip to content

Commit 6d84878

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
docs: add Android Interfaces cross-reference section to README
Explain the ndk/jni/aidl ecosystem with a Mermaid diagram showing how each library connects to the Android platform, a comparison table, and guidance on when to use which.
1 parent 8bd3a4e commit 6d84878

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,65 @@
77

88
Idiomatic Go bindings for the Android NDK, auto-generated from C headers to ensure full coverage and easy maintenance.
99

10+
## Android Interfaces for Go
11+
12+
This project is part of a family of three Go libraries that cover the major Android interface surfaces. Each wraps a different layer of the Android platform:
13+
14+
```mermaid
15+
graph TD
16+
subgraph "Go application"
17+
GO["Go code"]
18+
end
19+
20+
subgraph "Interface libraries"
21+
NDK["<b>ndk</b><br/>C API bindings via cgo"]
22+
JNI["<b>jni</b><br/>Java API bindings via JNI+cgo"]
23+
AIDL["<b>aidl</b><br/>Binder IPC, pure Go"]
24+
end
25+
26+
subgraph "Android platform"
27+
CAPI["NDK C libraries<br/>(libcamera2ndk, libaaudio,<br/>libEGL, libvulkan, ...)"]
28+
JAVA["Java SDK<br/>(android.bluetooth,<br/>android.location, ...)"]
29+
BINDER["/dev/binder<br/>kernel driver"]
30+
SYSSVCS["System services<br/>(ActivityManager,<br/>PowerManager, ...)"]
31+
end
32+
33+
GO --> NDK
34+
GO --> JNI
35+
GO --> AIDL
36+
37+
NDK -- "cgo / #include" --> CAPI
38+
JNI -- "cgo / JNIEnv*" --> JAVA
39+
AIDL -- "ioctl syscalls" --> BINDER
40+
BINDER --> SYSSVCS
41+
JAVA -. "internally uses" .-> BINDER
42+
CAPI -. "some use" .-> BINDER
43+
```
44+
45+
| Library | Interface | Requires | Best for |
46+
|---|---|---|---|
47+
| **[ndk](https://github.com/xaionaro-go/ndk)** (this project) | Android NDK C APIs | cgo + NDK toolchain | High-performance hardware access: camera, audio, sensors, OpenGL/Vulkan, media codecs |
48+
| **[jni](https://github.com/xaionaro-go/jni)** | Java Android SDK via JNI | cgo + JNI + JVM/ART | Java-only APIs with no NDK equivalent: Bluetooth, WiFi, NFC, location, telephony, content providers |
49+
| **[aidl](https://github.com/xaionaro-go/aidl)** | Binder IPC (system services) | pure Go (no cgo) | Direct system service calls without Java: works on non-Android Linux with binder, minimal footprint |
50+
51+
### When to use which
52+
53+
- **Start with ndk** when the NDK provides a C API for what you need (camera, audio, sensors, EGL/Vulkan, media codecs). These are the lowest-latency, lowest-overhead bindings since they go straight from Go to the C library via cgo.
54+
55+
- **Use jni** when you need a Java Android SDK API that the NDK does not expose. Examples: Bluetooth discovery, WiFi P2P, NFC tag reading, location services, telephony, content providers, notifications. JNI is also the right choice when you need to interact with Java components (Activities, Services, BroadcastReceivers) or when you need the gRPC remote-access layer.
56+
57+
- **Use aidl** when you want pure-Go access to Android system services without any cgo dependency. This is ideal for lightweight tools, CLI programs, or scenarios where you want to talk to the binder driver from a non-Android Linux system. AIDL covers the same system services that Java SDK wraps (ActivityManager, PowerManager, etc.) but at the wire-protocol level.
58+
59+
- **Combine them** when your application needs multiple layers. For example, a streaming app might use **ndk** for camera capture and audio encoding, **jni** for Bluetooth controller discovery, and **aidl** for querying battery status from a companion daemon.
60+
61+
### How they relate to each other
62+
63+
All three libraries talk to the same Android system services, but through different paths:
64+
65+
- The **NDK C APIs** are provided by Google as stable C interfaces to Android platform features. Some (camera, sensors, audio) internally use binder IPC to talk to system services; others (EGL, Vulkan, OpenGL) talk directly to kernel drivers. The `ndk` library wraps these C APIs via cgo.
66+
- The **Java SDK** uses binder IPC internally for system service access (BluetoothManager, LocationManager, etc.), routing calls through the Android Runtime (ART/Dalvik). The `jni` library calls into these Java APIs via the JNI C interface and cgo.
67+
- The **AIDL binder protocol** is the underlying IPC mechanism that system-facing NDK and Java SDK APIs use. The `aidl` library implements this protocol directly in pure Go, bypassing both C and Java layers entirely.
68+
1069
## Requirements
1170

1271
- **Android NDK r28** (28.0.13004108) or later

0 commit comments

Comments
 (0)