What problem does it solve?
Android JNI integrations with Rust are error-prone due to thread lifecycles, local references, and marshaling choices. This skill consolidates canonical patterns to ensure safe, predictable interactions between Rust and Java/Kotlin on Android; it emphasizes panic containment, AttachCurrentThread/DetachCurrentThread discipline, local-ref frame management, JNIEnv lifetime across awaits, and efficient data marshaling for hot paths.
Core Features & Use Cases
- Panic containment: ensure panics do not unwind across JNI boundaries.
- Thread lifecycle discipline: enforce AttachCurrentThread/DetachCurrentThread usage for non-JVM Rust threads.
- Local reference safety: apply frame-based local-reference handling to avoid JniLocalReferenceTableOverflow.
- Async safety: prohibit crossing JNIEnv across await boundaries; use separate tasks with proper JNI attachment.
- Performance-focused marshaling: prefer DirectByteBuffer over JByteArray copies for hot-path data.
- Use cases include authoring or reviewing JNI exports across ripdpi-android, ripdpi-tunnel-android, ripdpi-warp-android, ripdpi-relay-android, or any JNI export in the project.
Quick Start
Follow the five canonical rules when creating or updating any JNI export to ensure safe, deterministic Java-Rust interactions.