rust-android-jni

Enforce safe JNI patterns for Android Rust bindings.

58|4|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/po4yka/RIPDPI --skill rust-android-jni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-android-jni
Source: https://github.com/po4yka/RIPDPI/tree/main/.claude/skills/rust-android-jni
Command: npx skills add https://github.com/po4yka/RIPDPI --skill rust-android-jni

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about rust-android-jni

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent Rust panics from unwinding across JNI boundaries in Android?

To prevent Rust panics from unwinding across JNI boundaries in Android, wrap your JNI export logic in catch_unwind. This ensures panic containment so unwinding never crosses into Java or Kotlin, maintaining safe and predictable interactions.

What is the best way to manage JNIEnv across async await boundaries in Rust?

Managing JNIEnv across async await boundaries in Rust requires prohibiting JNIEnv from crossing await points. You must use separate tasks with proper AttachCurrentThread discipline to ensure safe thread lifecycle management during concurrent operations.

Why does my Android JNI integration cause a JniLocalReferenceTableOverflow error?

A JniLocalReferenceTableOverflow error occurs in Android JNI integrations when local references are not properly managed. Applying frame-based local-reference handling ensures local reference safety and prevents table overflow during Rust and Java interactions.

Should I use DirectByteBuffer or JByteArray for marshaling hot-path data in Rust JNI?

For marshaling hot-path data in Rust JNI, prefer DirectByteBuffer over JByteArray copies. DirectByteBuffer provides performance-focused memory handling by avoiding data copying, making it optimal for efficient data marshaling in Android bindings.

Do I need AttachCurrentThread for Rust threads making JNI calls on Android?

Yes, you need AttachCurrentThread for non-JVM Rust threads making JNI calls on Android. Enforcing AttachCurrentThread and DetachCurrentThread discipline ensures proper thread lifecycle management and safe JNIEnv access for concurrent operations.