The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Idiomatic Go bindings for the Java Native Interface and 53 Android Java API packages, auto-generated from YAML specs to ensure full coverage and easy maintenance.
For remote Android API access over gRPC, see jni-proxy.
Android Interfaces for Go
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:
graph TD
subgraph "Go application"
GO["Go code"]
end
subgraph "Interface libraries"
NDK["<b>ndk</b><br/>C API bindings via cgo"]
JNI["<b>jni</b><br/>Java API bindings via JNI+cgo"]
AIDL["<b>binder</b><br/>Binder IPC, pure Go"]
end
subgraph "Android platform"
CAPI["NDK C libraries<br/>(libcamera2ndk, libaaudio,<br/>libEGL, libvulkan, ...)"]
JAVA["Java SDK<br/>(android.bluetooth,<br/>android.location, ...)"]
BINDER["/dev/binder<br/>kernel driver"]
SYSSVCS["System services<br/>(ActivityManager,<br/>PowerManager, ...)"]
end
GO --> NDK
GO --> JNI
GO --> AIDL
NDK -- "cgo / #include" --> CAPI
JNI -- "cgo / JNIEnv*" --> JAVA
AIDL -- "ioctl syscalls" --> BINDER
BINDER --> SYSSVCS
JAVA -. "internally uses" .-> BINDER
CAPI -. "some use" .-> BINDER
Direct system service calls without Java: works on non-Android Linux with binder, minimal footprint
When to use which
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.
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.
Use binder 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.
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 binder for querying battery status from a companion daemon.
How they relate to each other
All three libraries talk to the same Android system services, but through different paths:
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.
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.
The AIDL binder protocol is the underlying IPC mechanism that system-facing NDK and Java SDK APIs use. The binder library implements this protocol directly in pure Go, bypassing both C and Java layers entirely.
Legend: Yellow = hand-written inputs, Green = generated intermediates, Blue = final consumer-facing output.
Layers
Raw CGo Layer (capi/) — Direct C bindings to JNI via vtable dispatch. Generated by jnigen.
Idiomatic JNI Layer (root package) — Safe Go types: VM, Env, Class, Object, Value, String, Array, MethodID, FieldID. All JNI exceptions converted to Go errors. Thread safety via VM.Do(). Generated by jnigen.
Android API Layer (53 packages) — High-level wrappers for Android system services. Each package provides a Manager type obtained via NewManager(ctx), with methods that call through JNI. Generated by javagen.
gRPC Layer — See jni-proxy for gRPC remote access (proto/grpc generation lives in that repo).
The JNI bindings and generated Android API packages are verified via jni-proxy E2E tests against real hardware.
Verified platforms (click to expand)
Type
Device
Android
API
ABI
Build
Date
Passed
Total
Phone
Pixel 8a
16
36
arm64-v8a
BP4A.260205.001
2026-03-15
21
21
Emulator
sdk_gphone64_x86_64
15
35
x86_64
2026-03-14
21
21
Tests cover: JNI version, class operations, method lookup + call, string round-trip, object operations, handle lifecycle, field access, exception handling, and full integration workflows. Camera recording, microphone recording, GPS location, and battery status are also verified on the Pixel 8a.
Adding a New Android API Package
Create spec/java/{package}.yaml with the Java class, methods, and go_import path.
Optionally create spec/overlays/java/{package}.yaml for customizations (extra methods, type overrides, name overrides).
Package jni provides idiomatic Go bindings for the Java Native Interface (JNI).
The root package exposes the idiomatic API: Env, VM, Class, Object, String,
Array, MethodID, FieldID, Value, and related types. All JNI exceptions are
converted to Go errors. Thread safety is handled via VM.Do().
The raw CGo bindings live in the capi/ sub-package. Most users should not
need to import capi/ directly.
Code in this package is generated by jnigen from spec/jni.yaml and
spec/overlays/jni.yaml. Do not edit generated files; edit the spec and
overlay instead, then run `make jni`.
EnsureProxyInit performs one-time initialization of the proxy
infrastructure (native method registration for GoInvocationHandler
and GoAbstractDispatch). Safe to call multiple times.
RegisterProxyHandler stores a basic ProxyHandler in the global registry
and returns a unique handler ID. This is used by the gRPC server layer
when creating abstract class adapter proxies (which dispatch without
a Method object). Call UnregisterProxyHandler when the proxy is no
longer needed.
SetProxyClassLoader sets a fallback ClassLoader that proxy init uses
to find GoInvocationHandler when JNI FindClass fails. Call this with
the APK's ClassLoader (from Context.getClassLoader()) before creating
any proxies. The caller must pass a global ref (not a local ref).
CAPIObject is an alias for capi.Object (C.jobject), exported so that
packages outside capi can reference the type for unsafe conversions
between different CGO compilation units.
EnvFromUintptr creates an Env from a uintptr-encoded JNIEnv pointer.
This is the convention used by gomobile (RunOnJVM) and other Go
Android frameworks.
The uintptr→unsafe.Pointer conversion is safe because JNI pointers
are C-allocated and not tracked by the Go garbage collector.
unsafe.Add(nil, ptr) is used instead of unsafe.Pointer(ptr) to avoid
a go vet "possible misuse of unsafe.Pointer" false positive.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallBooleanMethod wraps the JNI CallBooleanMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallByteMethod wraps the JNI CallByteMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallCharMethod wraps the JNI CallCharMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallDoubleMethod wraps the JNI CallDoubleMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallFloatMethod wraps the JNI CallFloatMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallIntMethod wraps the JNI CallIntMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallLongMethod wraps the JNI CallLongMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualBooleanMethod wraps the JNI CallNonvirtualBooleanMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualByteMethod wraps the JNI CallNonvirtualByteMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualCharMethod wraps the JNI CallNonvirtualCharMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualDoubleMethod wraps the JNI CallNonvirtualDoubleMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualFloatMethod wraps the JNI CallNonvirtualFloatMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualIntMethod wraps the JNI CallNonvirtualIntMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualLongMethod wraps the JNI CallNonvirtualLongMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualObjectMethod wraps the JNI CallNonvirtualObjectMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualShortMethod wraps the JNI CallNonvirtualShortMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallNonvirtualVoidMethod wraps the JNI CallNonvirtualVoidMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallObjectMethod wraps the JNI CallObjectMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallShortMethod wraps the JNI CallShortMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticBooleanMethod wraps the JNI CallStaticBooleanMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticByteMethod wraps the JNI CallStaticByteMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticCharMethod wraps the JNI CallStaticCharMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticDoubleMethod wraps the JNI CallStaticDoubleMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticFloatMethod wraps the JNI CallStaticFloatMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticIntMethod wraps the JNI CallStaticIntMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticLongMethod wraps the JNI CallStaticLongMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticObjectMethod wraps the JNI CallStaticObjectMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticShortMethod wraps the JNI CallStaticShortMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallStaticVoidMethod wraps the JNI CallStaticVoidMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
CallVoidMethod wraps the JNI CallVoidMethodA function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetBooleanField wraps the JNI GetBooleanField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetDoubleField wraps the JNI GetDoubleField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetFloatField wraps the JNI GetFloatField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetObjectClass wraps the JNI GetObjectClass function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetObjectField wraps the JNI GetObjectField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetShortField wraps the JNI GetShortField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticBooleanField wraps the JNI GetStaticBooleanField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticByteField wraps the JNI GetStaticByteField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticCharField wraps the JNI GetStaticCharField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticDoubleField wraps the JNI GetStaticDoubleField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticFieldID wraps the JNI GetStaticFieldID function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticFloatField wraps the JNI GetStaticFloatField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticIntField wraps the JNI GetStaticIntField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticLongField wraps the JNI GetStaticLongField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticMethodID wraps the JNI GetStaticMethodID function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticObjectField wraps the JNI GetStaticObjectField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GetStaticShortField wraps the JNI GetStaticShortField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
NewProxy creates a java.lang.reflect.Proxy that implements the given
Java interfaces, dispatching all method calls to the Go handler.
The handler receives the method name and an array of arguments (as
*Object, with boxed primitives). It returns a result *Object (or nil
for void) and an optional error (which becomes a RuntimeException on
the Java side).
The returned cleanup function MUST be called when the proxy is no
longer needed, to remove the handler from the global registry.
Failing to call cleanup leaks memory.
NewProxyFull creates a java.lang.reflect.Proxy like NewProxy, but
dispatches to a ProxyHandlerFull that also receives the
java.lang.reflect.Method object. This allows the handler to inspect
the method's return type (e.g. to detect void callbacks).
See NewProxy for full documentation on usage and cleanup semantics.
SetBooleanField wraps the JNI SetBooleanField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetDoubleField wraps the JNI SetDoubleField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetFloatField wraps the JNI SetFloatField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetObjectField wraps the JNI SetObjectField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetShortField wraps the JNI SetShortField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticBooleanField wraps the JNI SetStaticBooleanField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticByteField wraps the JNI SetStaticByteField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticCharField wraps the JNI SetStaticCharField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticDoubleField wraps the JNI SetStaticDoubleField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticFloatField wraps the JNI SetStaticFloatField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticIntField wraps the JNI SetStaticIntField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticLongField wraps the JNI SetStaticLongField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticObjectField wraps the JNI SetStaticObjectField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
SetStaticShortField wraps the JNI SetStaticShortField function.
This is a low-level call. Prefer the typed wrappers (e.g. packages under
app/, content/, provider/) which handle JNI signatures, local/global
reference management, and error checking automatically. Use Env methods
directly only as a last resort for functionality not yet covered by a
typed wrapper.
GlobalRef is an Object that has been promoted to a JNI global reference.
It has the same layout as Object so that it can be cast to *Class or
other reference types via unsafe.Pointer when needed.
ObjectFromPtr wraps a raw C jobject pointer in an Object, mirroring
VMFromPtr. Prefer ObjectFromUintptr for NativeActivity callbacks to
avoid go vet "possible misuse of unsafe.Pointer" warnings:
ObjectFromUintptr wraps a uintptr-encoded jobject in an Object.
This is the convention used by gomobile (RunOnJVM passes context
as uintptr) and other Go Android frameworks.
unsafe.Add(nil, ptr) is used instead of unsafe.Pointer(ptr) to avoid
a go vet "possible misuse of unsafe.Pointer" false positive.
ProxyHandler is a Go function that handles method invocations on a
Java interface proxy. It receives the method name and arguments, and
returns a result object (or nil for void methods) and an optional error.
ProxyHandlerFull is like ProxyHandler but also receives the
java.lang.reflect.Method object for return type inspection
(e.g. detecting void callbacks via method.getReturnType()).
VMFromUintptr creates a VM from a uintptr-encoded JavaVM pointer.
This is the convention used by gomobile (RunOnJVM), Gio (app.JavaVM),
and other Go Android frameworks.
The uintptr→unsafe.Pointer conversion is safe because JNI pointers
are C-allocated and not tracked by the Go garbage collector.
unsafe.Add(nil, ptr) is used instead of unsafe.Pointer(ptr) to avoid
a go vet "possible misuse of unsafe.Pointer" false positive.
Do pins the calling goroutine to an OS thread, attaches it to the JVM
(if not already attached), executes fn with a valid *Env, and detaches
if it was the one that attached.
This is the primary entry point for all JNI operations. It ensures:
The goroutine stays on the same OS thread for the duration of fn.
The OS thread has a valid JNIEnv (attaching if necessary).
The thread is detached after fn returns (only if Do attached it).
It is safe to nest Do calls. An inner Do finds the thread already
attached via GetEnv and neither re-attaches nor detaches. Go
reference-counts LockOSThread/UnlockOSThread, so nesting is safe.