android-jni

Implement and review JNI bridges between Android Java or Kotlin and C or C++ native code.

1|Updated Feb 28, 2026
One-click install
npx skills add https://github.com/Binh230199/ai --skill android-jni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-jni
Source: https://github.com/Binh230199/ai/tree/main/.github/skills/android-jni
Command: npx skills add https://github.com/Binh230199/ai --skill android-jni

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you write, review, and debug JNI code that connects Android Java or Kotlin with C or C++ native code, reducing crashes, memory leaks, and threading bugs across the native boundary.

Core Features & Use Cases

  • Native method implementation: Define and name JNI entry points correctly for Java and Kotlin classes.
  • Type and memory safety: Handle strings, arrays, local references, global references, and exception propagation without leaking resources.
  • Threading and callbacks: Attach background native threads to the JVM, cache class and method IDs, and call Java listeners safely from C++.
  • Use case: When an Android app needs to stream audio or process hardware data in native code, this Skill guides the JNI layer so the bridge is stable, efficient, and maintainable.

Quick Start

Use the android-jni skill to review or implement the JNI bridge for your Android class or method and check naming, type conversion, reference lifetimes, exceptions, and threading behavior.

Frequently Asked Questions about android-jni

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

FAQPage Schema
How do I safely pass strings and arrays between Kotlin and C++ using Android JNI?

You can safely transfer strings and arrays between Kotlin and C++ by applying correct JNI type mapping and managing local reference lifetimes, preventing memory leaks and crashes during native data exchange.

Why does my Android NDK background thread crash when calling a Java listener?

Android NDK background thread crashes when calling a Java listener happen because the native thread is not attached to the JavaVM. You must attach the thread, cache class and method IDs, and handle global references safely.

What is the correct way to name native methods for JNI bridges in Android?

The correct way to name native methods for JNI bridges in Android involves using proper JNI entry point naming conventions and initializing them within JNI_OnLoad to ensure the Java or Kotlin runtime correctly links to your C or C++ functions.

How do I handle exceptions and global references in Android NDK to avoid memory leaks?

To handle exceptions and global references in Android NDK and avoid memory leaks, you must propagate exceptions across the JNI boundary and carefully manage the lifetime of both local and global references throughout your native method execution.

Does this JNI guidance apply to AAOS projects as well as standard Android apps?

Yes, this JNI guidance applies to AAOS projects as well as standard Android apps. It supports stable and efficient native bridges for streaming audio or processing hardware data in both standard Android and Android Automotive environments.

What's the best way to implement JNI_OnLoad initialization for Android native bridges?

The best way to implement JNI_OnLoad initialization for Android native bridges is to cache required class and method IDs early, ensuring safe and efficient callbacks from C++ to Java listeners while maintaining correct JavaVM thread attachment.