/android-skills:android-jni-securityfrom Android Skills
Audits and secures Android JNI boundaries against buffer overflows, memory pinning, TOCTOU races, hardcoded native secrets, cross-thread reference crashes, and unhandled JVM exceptions.
Ships in Android Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill provides rules and code patterns to secure Android JNI boundaries. Follow these patterns to prevent buffer overflows, pinned memory leaks, and Time-of-Check to Time-of-Use (TOCTOU) file races. They also prevent hardcoded native secrets, cross-thread reference crashes, and unhandled pending JVM exceptions.
.so libraries.JNIEnv* pointer must NEVER be shared or cached across threads.AttachCurrentThread, DetachCurrentThread).jobject, jclass, jstring, jarray) valid only during the active native call.NewGlobalRef) that keeps a Java object reachable across threads and calls until freed with DeleteGlobalRef.fopen or open runs.ExceptionCheck(), then free resources and return, or clear and handle the failure..so libraries..so binary hardening, suggest NDK visibility flags (-fvisibility=hidden, -Wl,--exclude-libs,ALL), symbol stripping, and the Play Integrity API.externalNativeBuild with cmake in build.gradle or build.gradle.kts, and include <jni.h> in C/C++. Ask for user confirmation before modifying Gradle build files or rebuilding the project interactively.android.os.ParcelFileDescriptor and android.security.keystore.* (API 23+ for AES-GCM in AndroidKeyStore).When managing JNI reference lifetimes, UTF-8 strings, or thread attachment, follow JNI tips. Evaluate every parameter crossing the JNI boundary against its C/C++ release contract:
| JNI Type | C/C++ Acquisition API | Risk if Unchecked or Unreleased | Required Cleanup Action |
|---|---|---|---|
jbyteArray (copy) | GetByteArrayRegion() | Stack or heap buffer overflow if length exceeds destination | Validate GetArrayLength() and check ExceptionCheck() (no release call needed) |
jbyteArray (in-place) | GetByteArrayElements() | Heap pinning leak or out-of-memory (OOM) nullptr dereference | Validate GetArrayLength(), check for nullptr, and call ReleaseByteArrayElements() on all paths |
jstring (input) | GetStringUTFChars() | Native UTF-8 buffer leak or OOM nullptr dereference | Check for nullptr and call ReleaseStringUTFChars() before DeleteLocalRef() |
jstring (output) | NewStringUTF() | Runtime abort when raw native bytes are not valid Modified UTF-8 | Sanitize text to valid Modified UTF-8 first, or return jbyteArray for binary data |
jobject / jclass (local) | GetObjectClass(), FindClass(), GetObjectField() | Local reference exhaustion in loops and on attached threads | Call DeleteLocalRef() when finished, especially in loops or attached threads |
jobject / jclass (cached) | NewGlobalRef() | Dangling local pointer crash across calls or threads if not promoted | Promote with NewGlobalRef() and free with DeleteGlobalRef() on teardown |
When passing untrusted inputs across JNI into C or C++ code, follow Use of native code. Validate array sizes in both managed wrappers and native C/C++ entry points before copying into fixed buffers:
IF (a Kotlin or Java class exposes a native method accepting arrays or
lengths) {
MUST declare the external (or native) method private.
MUST expose a public wrapper that validates non-empty inputs and enforces
maximum byte length bounds before calling JNI.
IN C/C++:
MUST verify array != nullptr and validate length > 0,
length <= kMaxBufferSize, and length <= env->GetArrayLength(array).
IF (bounds validation fails) {
MUST throw java/lang/IllegalArgumentException using
env->ThrowNew and return immediately before copying memory.
}
IF (copying bytes into a native buffer) {
MUST copy with env->GetByteArrayRegion(array, 0, length, buf) and
check env->ExceptionCheck().
}
IF (accessing or mutating elements in place) {
MUST check that env->GetByteArrayElements(array, nullptr) returns
a non-null pointer.
MUST call env->ReleaseByteArrayElements(array, ptr, mode) (0 to
copy back changes, or JNI_ABORT for read-only access) on every
return path.
}
}
IF (native code accesses a direct ByteBuffer or constructs jstring output) {
MUST verify env->GetDirectBufferAddress(buf) != nullptr and validate byte
offsets against env->GetDirectBufferCapacity(buf).
NEVER pass raw file or network bytes directly to env->NewStringUTF().
MUST sanitize text bytes to valid Modified UTF-8 before NewStringUTF(), or
return a jbyteArray for arbitrary binary data.
}
Never pass raw file path strings across JNI after checking file properties in Kotlin or Java:
IF (native C/C++ code reads or writes an application or shared file) {
NEVER pass a raw file path String (jstring) across JNI to fopen() or
open().
MUST canonicalize app-internal paths inside context.filesDir and open a
ParcelFileDescriptor with the narrowest required mode (for example
MODE_READ_ONLY). For content:// URIs, open the descriptor through
context.contentResolver.openFileDescriptor(uri, "r").
MUST pass only the integer descriptor (pfd.fd) across JNI (jint fd)
inside .use { ... }, and perform I/O on fd in C/C++ (pread or read).
NEVER call close(fd), pass fd directly to fdopen(), or retain fd
after .use { ... } returns because ParcelFileDescriptor owns it. Call
dup(fd) if native code needs an owned descriptor copy.
}
When storing or deriving cryptographic keys in Android apps, follow Hardcoded cryptographic secrets. Never embed static cryptographic keys or salts in C/C++ source files:
IF (an application encrypts, decrypts, or authenticates payloads across JNI) {
NEVER hardcode secret keys, passwords, or salts in C/C++ arrays or string
literals.
MUST generate and store master keys in AndroidKeyStore
(KeyStore.getInstance("AndroidKeyStore")) and run Cipher operations in
Kotlin or Java.
IF (native C/C++ cryptographic processing is required) {
MUST pass only a short-lived, unwrapped per-session data encryption key
for that single call rather than embedding a static key.
}
MUST overwrite transient sensitive native buffers before freeing memory
using a volatile byte loop (volatile uint8_t*), or memset_explicit when
minSdk is 34 or higher.
MUST copy sensitive JNI byte arrays with GetByteArrayRegion into an owned
buffer that you zero, or unpin GetByteArrayElements pointers with
ReleaseByteArrayElements(..., JNI_ABORT).
}
Never share JNIEnv* or local references across threads. Check for pending JVM
exceptions after every JNI call:
IF (native code caches a callback object or invokes JNI from a background
thread) {
NEVER store a raw local jobject, jclass, or JNIEnv* in a static or
global C/C++ variable.
MUST cache JavaVM* (via JNI_OnLoad or env->GetJavaVM) and promote
cached objects with env->NewGlobalRef(obj).
MUST guard shared global references with a mutex and acquire a
NewLocalRef under the lock before calling out, or stop worker threads
before calling env->DeleteGlobalRef(globalRef).
ON A NATIVE BACKGROUND THREAD:
MUST check gJavaVm->GetEnv(..., JNI_VERSION_1_6) if the helper may run
on an already-attached thread; call AttachCurrentThread only on
JNI_EDETACHED, and call DetachCurrentThread only if this code
attached the thread.
MUST resolve app classes via GetObjectClass on a cached instance or a
global jclass cached in JNI_OnLoad, because FindClass on a
natively attached thread uses the system class loader.
MUST delete local references (DeleteLocalRef), log and clear pending
exceptions (ExceptionDescribe() then ExceptionClear()), and detach
if attached by this call.
}
IF (native code calls FindClass, GetMethodID, GetFieldID, Call*Method,
GetObjectField, or GetStringUTFChars) {
NEVER let C++ exceptions cross a JNIEXPORT boundary; catch them in C++ and
translate them with env->ThrowNew().
MUST check env->ExceptionCheck() and null returns after EACH call before
invoking the next JNI function.
IF (env->ExceptionCheck() is true in a Kotlin or Java JNI entry point) {
MUST release acquired native buffers and local references, then return
immediately so the exception propagates; call ExceptionClear() only
when native code handles the failure itself.
}
MUST annotate JNI-referenced Kotlin or Java members with @Keep (or add
-keepclassmembers R8 rules). This prevents release shrinking from causing
NoSuchMethodError or NoSuchFieldError.
MUST call env->DeleteLocalRef on temporary local object, class, and
string references before returning.
}
Declare external methods private and validate sizes in a public Kotlin
wrapper. Re-verify GetArrayLength in C++ and copy read-only bytes with
GetByteArrayRegion so the managed array is never pinned. Keep C++ JNI symbol
names aligned with the Kotlin external fun names, or the first call throws
UnsatisfiedLinkError.
ByteArray within the maximum frame size.GetByteArrayRegion, and throws IllegalArgumentException on invalid sizes.object SecureNativeDataProcessor {
private const val MAX_PACKET_SIZE = 2048
init {
System.loadLibrary("secure_bridge")
}
// Keep raw external declarations private so callers cannot bypass validation
@JvmStatic
private external fun processPacketNative(packet: ByteArray, length: Int): Int
@JvmStatic
fun processPacketSafely(packet: ByteArray): Int {
require(packet.isNotEmpty()) {
"Packet must not be empty"
}
require(packet.size <= MAX_PACKET_SIZE) {
"Packet size (${packet.size}) exceeds maximum ($MAX_PACKET_SIZE)"
}
return processPacketNative(packet, packet.size)
}
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_example_snippets_security_jni_SecureNativeDataProcessor_processPacketNative(
JNIEnv* env,
jclass /*clazz*/,
jbyteArray packet,
jint length) {
constexpr jsize kMaxFrameSize = 2048;
if (packet == nullptr) {
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
if (exClass != nullptr) {
env->ThrowNew(exClass, "Packet array must not be null");
env->DeleteLocalRef(exClass);
}
return -1;
}
jsize arrayLength = env->GetArrayLength(packet);
if (length <= 0 || length > kMaxFrameSize || length > arrayLength) {
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
if (exClass != nullptr) {
env->ThrowNew(exClass, "Packet length out of valid bounds");
env->DeleteLocalRef(exClass);
}
return -1;
}
// Copy into a bounds-checked native buffer without pinning the managed array
uint8_t frameBuffer[kMaxFrameSize];
env->GetByteArrayRegion(
packet, 0, length, reinterpret_cast<jbyte*>(frameBuffer));
if (env->ExceptionCheck()) {
return -1;
}
uint32_t checksum = 0;
for (jint i = 0; i < length; ++i) {
checksum = (checksum * 31u) + static_cast<uint32_t>(frameBuffer[i]);
}
return static_cast<jint>(checksum);
}
Open files in Kotlin with ParcelFileDescriptor.open and pass only the integer
descriptor (pfd.fd) to C++. Borrow fd with pread without closing it so
ParcelFileDescriptor retains ownership.
context (Context) and fileName (String).fd in C++ and sanitizes bytes to valid Modified UTF-8 before NewStringUTF.class SecureNativeFileLoader(private val context: Context) {
companion object {
init {
System.loadLibrary("secure_bridge")
}
}
fun readVerifiedHeader(fileName: String): String {
val baseDir = context.filesDir.canonicalFile
val targetFile = File(baseDir, fileName).canonicalFile
require(targetFile.path.startsWith("${baseDir.path}${File.separator}")) {
"Invalid file path outside app files directory"
}
// Open the file in managed code and pass only the integer FD to C++
// to remove the managed-to-native path re-open race window.
return ParcelFileDescriptor.open(
targetFile,
ParcelFileDescriptor.MODE_READ_ONLY,
).use { pfd ->
readHeaderFromFdNative(pfd.fd)
}
}
private external fun readHeaderFromFdNative(fd: Int): String
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_snippets_security_jni_SecureNativeFileLoader_readHeaderFromFdNative(
JNIEnv* env,
jobject /*thiz*/,
jint fd) {
if (fd < 0) {
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
if (exClass != nullptr) {
env->ThrowNew(exClass, "Invalid file descriptor");
env->DeleteLocalRef(exClass);
}
return nullptr;
}
char header[256];
std::memset(header, 0, sizeof(header));
// Borrow fd with pread; never close(fd) because ParcelFileDescriptor owns it
ssize_t bytesRead = pread(fd, header, sizeof(header) - 1, 0);
if (bytesRead < 0) {
jclass ioExClass = env->FindClass("java/io/IOException");
if (ioExClass != nullptr) {
env->ThrowNew(ioExClass, "Failed to read header from descriptor");
env->DeleteLocalRef(ioExClass);
}
return nullptr;
}
// Sanitize to printable 7-bit ASCII so NewStringUTF never receives invalid Modified UTF-8
for (ssize_t i = 0; i < bytesRead; ++i) {
unsigned char c = static_cast<unsigned char>(header[i]);
if (c == 0 || c > 0x7f) {
header[i] = '?';
}
}
header[bytesRead] = '\0';
return env->NewStringUTF(header);
}
Manage master keys in AndroidKeyStore instead of hardcoding secrets in C++.
Copy transient sensitive bytes into an owned C++ buffer with
GetByteArrayRegion and wipe that buffer through a volatile uint8_t* loop
(or memset_explicit on API 34+) before returning.
payload (ByteArray).AndroidKeyStore AES-GCM key.object SecureNativeCryptoBridge {
private const val ANDROID_KEYSTORE = "AndroidKeyStore"
private const val KEY_ALIAS = "app_master_aes_key"
private const val TRANSFORMATION = "AES/GCM/NoPadding"
init {
System.loadLibrary("secure_bridge")
}
@JvmStatic
private external fun framePlaintextNative(plaintext: ByteArray): ByteArray
@JvmStatic
fun encryptAndProcess(payload: ByteArray): ByteArray {
val framedPlaintext = framePlaintextNative(payload)
try {
val cipher = Cipher.getInstance(TRANSFORMATION)
cipher.init(Cipher.ENCRYPT_MODE, getOrCreateSecretKey())
val iv = cipher.iv
val encrypted = cipher.doFinal(framedPlaintext)
// Prepend IV length (1 byte) + IV + authenticated ciphertext
val output = ByteArray(1 + iv.size + encrypted.size)
output[0] = iv.size.toByte()
System.arraycopy(iv, 0, output, 1, iv.size)
System.arraycopy(encrypted, 0, output, 1 + iv.size, encrypted.size)
return output
} finally {
framedPlaintext.fill(0)
}
}
private fun getOrCreateSecretKey(): SecretKey {
val keyStore = KeyStore.getInstance(ANDROID_KEYSTORE).apply { load(null) }
val existing = keyStore.getEntry(KEY_ALIAS, null) as? KeyStore.SecretKeyEntry
if (existing != null) {
return existing.secretKey
}
val keyGenerator = KeyGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES,
ANDROID_KEYSTORE,
)
val spec = KeyGenParameterSpec.Builder(
KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT,
)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.setKeySize(256)
.build()
keyGenerator.init(spec)
return keyGenerator.generateKey()
}
}
namespace {
void secureZeroMemory(void* ptr, size_t len) {
volatile uint8_t* p = reinterpret_cast<volatile uint8_t*>(ptr);
while (len-- > 0) {
*p++ = 0;
}
}
} // namespace
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_com_example_snippets_security_jni_SecureNativeCryptoBridge_framePlaintextNative(
JNIEnv* env,
jclass /*clazz*/,
jbyteArray plaintext) {
constexpr jsize kMaxPayloadSize = 65536;
if (plaintext == nullptr) {
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
if (exClass != nullptr) {
env->ThrowNew(exClass, "Plaintext array must not be null");
env->DeleteLocalRef(exClass);
}
return nullptr;
}
jsize length = env->GetArrayLength(plaintext);
if (length <= 0 || length > kMaxPayloadSize) {
jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
if (exClass != nullptr) {
env->ThrowNew(exClass, "Plaintext length out of valid bounds");
env->DeleteLocalRef(exClass);
}
return nullptr;
}
// Copy sensitive bytes into an owned buffer via GetByteArrayRegion without pinning
std::vector<uint8_t> sensitiveBuffer(static_cast<size_t>(length) + 1);
sensitiveBuffer[0] = 0x01; // Protocol frame version
env->GetByteArrayRegion(
plaintext, 0, length, reinterpret_cast<jbyte*>(sensitiveBuffer.data() + 1));
if (env->ExceptionCheck()) {
secureZeroMemory(sensitiveBuffer.data(), sensitiveBuffer.size());
return nullptr;
}
jbyteArray framed = env->NewByteArray(length + 1);
if (framed != nullptr && !env->ExceptionCheck()) {
env->SetByteArrayRegion(
framed, 0, length + 1, reinterpret_cast<const jbyte*>(sensitiveBuffer.data()));
}
// Wipe transient sensitive native memory before returning to managed code
secureZeroMemory(sensitiveBuffer.data(), sensitiveBuffer.size());
return framed;
}
Promote cross-thread callbacks with NewGlobalRef, guard them with a mutex, and
free them with DeleteGlobalRef. Attach native worker threads to JavaVM*
using AttachCurrentThread and DetachCurrentThread.
JNIEnv*, logs and clears pending exceptions, and frees global and local references before detaching.namespace {
JavaVM* gJavaVm = nullptr;
std::mutex gListenerMutex;
jobject gListenerGlobalRef = nullptr;
} // namespace
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* /*reserved*/) {
gJavaVm = vm;
return JNI_VERSION_1_6;
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_snippets_security_jni_SecureSessionMonitor_registerListener(
JNIEnv* env,
jobject /*thiz*/,
jobject listener) {
if (gJavaVm == nullptr) {
env->GetJavaVM(&gJavaVm);
}
std::lock_guard<std::mutex> lock(gListenerMutex);
if (gListenerGlobalRef != nullptr) {
env->DeleteGlobalRef(gListenerGlobalRef);
gListenerGlobalRef = nullptr;
}
if (listener != nullptr) {
// Promote local jobject to a Global Reference so it stays reachable across threads
gListenerGlobalRef = env->NewGlobalRef(listener);
}
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_snippets_security_jni_SecureSessionMonitor_dispatchBackgroundCheck(
JNIEnv* /*env*/,
jobject /*thiz*/) {
std::thread worker([]() {
if (gJavaVm == nullptr) {
return;
}
JNIEnv* threadEnv = nullptr;
if (gJavaVm->AttachCurrentThread(&threadEnv, nullptr) != JNI_OK ||
threadEnv == nullptr) {
return;
}
jobject localListener = nullptr;
{
std::lock_guard<std::mutex> lock(gListenerMutex);
if (gListenerGlobalRef != nullptr) {
localListener = threadEnv->NewLocalRef(gListenerGlobalRef);
}
}
if (localListener != nullptr) {
jclass listenerClass = threadEnv->GetObjectClass(localListener);
if (listenerClass != nullptr && !threadEnv->ExceptionCheck()) {
jmethodID methodId = threadEnv->GetMethodID(
listenerClass, "onStatusUpdate", "(I)V");
if (methodId != nullptr && !threadEnv->ExceptionCheck()) {
threadEnv->CallVoidMethod(localListener, methodId, 1);
}
threadEnv->DeleteLocalRef(listenerClass);
}
threadEnv->DeleteLocalRef(localListener);
}
// Log and clear any pending JVM exception before detaching the native thread
if (threadEnv->ExceptionCheck()) {
threadEnv->ExceptionDescribe();
threadEnv->ExceptionClear();
}
gJavaVm->DetachCurrentThread();
});
worker.detach();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_snippets_security_jni_SecureSessionMonitor_unregisterListener(
JNIEnv* env,
jobject /*thiz*/) {
std::lock_guard<std::mutex> lock(gListenerMutex);
if (gListenerGlobalRef != nullptr) {
env->DeleteGlobalRef(gListenerGlobalRef);
gListenerGlobalRef = nullptr;
}
}
Check env->ExceptionCheck() and null returns after every JNI lookup, method
call, field read, or string acquisition. Free local references with
DeleteLocalRef on every return path.
jobject passed across JNI.extern "C"
JNIEXPORT jboolean JNICALL
Java_com_example_snippets_security_jni_SecureConfigParser_validateOptions(
JNIEnv* env,
jclass /*clazz*/,
jobject options) {
if (options == nullptr) {
return JNI_FALSE;
}
jclass optionsClass = env->GetObjectClass(options);
if (optionsClass == nullptr || env->ExceptionCheck()) {
return JNI_FALSE;
}
jmethodID buildHeaderMethod = env->GetMethodID(
optionsClass, "buildAuthHeader", "()Ljava/lang/String;");
if (buildHeaderMethod == nullptr || env->ExceptionCheck()) {
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
// Check ExceptionCheck() immediately after CallObjectMethod before any other JNI call
jstring headerStr = static_cast<jstring>(
env->CallObjectMethod(options, buildHeaderMethod));
if (env->ExceptionCheck() || headerStr == nullptr) {
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
const char* headerChars = env->GetStringUTFChars(headerStr, nullptr);
if (headerChars == nullptr || env->ExceptionCheck()) {
env->DeleteLocalRef(headerStr);
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
bool validHeader = headerChars[0] != '\0';
env->ReleaseStringUTFChars(headerStr, headerChars);
env->DeleteLocalRef(headerStr);
jfieldID hostField = env->GetFieldID(
optionsClass, "host", "Ljava/lang/String;");
if (hostField == nullptr || env->ExceptionCheck()) {
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
jfieldID accountField = env->GetFieldID(
optionsClass, "accountId", "Ljava/lang/String;");
if (accountField == nullptr || env->ExceptionCheck()) {
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
jstring hostStr = static_cast<jstring>(
env->GetObjectField(options, hostField));
if (env->ExceptionCheck() || hostStr == nullptr) {
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
jstring accountStr = static_cast<jstring>(
env->GetObjectField(options, accountField));
if (env->ExceptionCheck() || accountStr == nullptr) {
env->DeleteLocalRef(hostStr);
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
const char* hostChars = env->GetStringUTFChars(hostStr, nullptr);
if (hostChars == nullptr || env->ExceptionCheck()) {
env->DeleteLocalRef(accountStr);
env->DeleteLocalRef(hostStr);
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
const char* accountChars = env->GetStringUTFChars(accountStr, nullptr);
if (accountChars == nullptr || env->ExceptionCheck()) {
env->ReleaseStringUTFChars(hostStr, hostChars);
env->DeleteLocalRef(accountStr);
env->DeleteLocalRef(hostStr);
env->DeleteLocalRef(optionsClass);
return JNI_FALSE;
}
bool nonEmpty = validHeader && hostChars[0] != '\0' && accountChars[0] != '\0';
env->ReleaseStringUTFChars(hostStr, hostChars);
env->ReleaseStringUTFChars(accountStr, accountChars);
env->DeleteLocalRef(accountStr);
env->DeleteLocalRef(hostStr);
env->DeleteLocalRef(optionsClass);
return nonEmpty ? JNI_TRUE : JNI_FALSE;
}
.so binaries.memcpy, strcpy, or sprintf without checking env->GetArrayLength(array) or GetDirectBufferCapacity(buf).jstring) across JNI to fopen or open after managed checks, or close() a borrowed ParcelFileDescriptor.NewStringUTF(), or let C++ exceptions escape across a JNIEXPORT boundary.jobject, jclass, or thread-local JNIEnv* in static or global C/C++ variables.env->ExceptionCheck() first.external or native buffer methods private and validate bounds in a public wrapper. Verify GetArrayLength in C++ and throw IllegalArgumentException via env->ThrowNew on invalid lengths.GetByteArrayRegion, or check GetByteArrayElements and GetStringUTFChars for nullptr and release them on all paths.ParcelFileDescriptor.open (or content:// URIs with ContentResolver.openFileDescriptor) and pass pfd.fd inside .use { } without closing fd in C++.AndroidKeyStore and zero transient native buffers (volatile uint8_t* or API 34+ memset_explicit) before freeing memory.NewGlobalRef under a lock, free them with DeleteGlobalRef, and attach threads safely via JavaVM*.env->ExceptionCheck() after each JNI call, release local references and return on pending exceptions, and mark JNI targets @Keep.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
android-security, jni-audit, native-code, ndk, c-cpp-security
npx claudepluginhub android/skills --plugin android-skills42 skills in this plugin
/adaptiveInstructions to make or update an app's UI so that it adapts to different Android devices including phones, tablets, foldables, laptops, desktop, TV, Auto, and XR. It includes how to handle different window sizes, pointing devices (such as mouse) and text entry devices (such as keyboard) using the Compose MediaQuery API, and how to preserve UI, navigation, scroll, and media playback state across configuration changes (such as folding/unfolding a foldable, rotating a device, or resizing a window). It also covers multi-pane layouts using Navigation3 Scenes, adaptive UI components (such as buttons) with varying target sizes, and adaptive layouts (including navigation areas - nav rails and nav bars) using the Compose Grid and FlexBox APIs. It also covers desktop experiences with keyboard shortcuts, tooltips and custom cursors./agp-9-upgradeUpgrades, or migrates, an Android project to use Android Gradle Plugin (AGP) version 9. Do not use this skill for migrating Kotlin Multiplatform (KMP) projects./android-cliProvides instructions for installing and using the `android` CLI. The `android` command-line tool is a critical tool for Android development and helps you create new Android projects, install APKs onto devices and emulators and launch and run apps on them, manage and interact with Android virtual devices (including screenshots and UI inspection), manage Android SDK components, inspect built artifacts (APK, AAB, JAR, AAR) for build and optimization details, render Compose previews, look up official Android documentation, and discover and install official Android skills./android-for-cars-parked-appsAdapt existing Android video streaming apps, games, and web browsers to run as parked apps on Android Auto and Android Automotive OS. Covers manifest configuration, Google Play hardware feature declarations, compatibility mode, back navigation affordances, orientation and display continuity, controllable system bar insets, irregular display cutouts, driver distraction lifecycle handling, MediaSession playback restrictions with CarUxRestrictionsManager, background audio while driving, and browser sensitive data protection. Use this skill when migrating, building, or auditing parked apps for cars to meet Car App Quality guidelines. Don't use for media audio apps, templated Car App Library navigation, point of interest, internet of things, weather, or communication apps designed for use while driving./android-intent-securityAudits, detects, and remediates Android Intent and component security vulnerabilities. Use this skill when auditing component configurations in AndroidManifest.xml (activities, services, receivers) or source code handling incoming Intents (getIntent, getParcelableExtra) to prevent Intent Redirection and unauthorized access. Don't use for network security, TLS configuration, or general runtime permission request flows./android-permissions-securityAudits, detects gaps, and remediates Android permissions and IPC component security vulnerabilities. Use when reviewing AndroidManifest.xml, defining custom permissions, securing Services, Receivers, and Providers, verifying caller signatures and UID using Binder, or implementing runtime permission flows.2 plugins ship this exact skill · first indexed Nov 24, 2026
Other plugins' skills for the same job