jni

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: CC0-1.0 Imports: 9 Imported by: 0

README ¶

jni

Go Reference Go Report Card Go Version

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
Library Interface Requires Best for
ndk Android NDK C APIs cgo + NDK toolchain High-performance hardware access: camera, audio, sensors, OpenGL/Vulkan, media codecs
jni (this project) Java Android SDK via JNI cgo + JNI + JVM/ART Java-only APIs with no NDK equivalent: Bluetooth, WiFi, NFC, location, telephony, content providers
binder Binder IPC (system services) pure Go (no cgo) 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.

Usage Examples

Bluetooth Discovery
import (
    "github.com/AndroidGoLab/jni"
    "github.com/AndroidGoLab/jni/app"
    "github.com/AndroidGoLab/jni/bluetooth"
)

    ctx, _ := app.NewContext(vm)
    adapter, _ := bluetooth.NewAdapter(ctx)
    defer adapter.Close()

    fmt.Println("Enabled:", adapter.IsEnabled())
    fmt.Println("Name:", adapter.GetName())

    devices, _ := adapter.GetBondedDevices()
    for _, d := range devices {
        fmt.Printf("  %s (%s)\n", d.Name, d.Address)
    }
Location
import (
    "github.com/AndroidGoLab/jni/app"
    "github.com/AndroidGoLab/jni/location"
)

    ctx, _ := app.NewContext(vm)
    mgr, _ := location.NewManager(ctx)
    defer mgr.Close()

    loc, _ := mgr.GetLastKnownLocation(location.GpsProvider)
    if loc != nil {
        fmt.Printf("lat=%.6f lon=%.6f\n", loc.Latitude, loc.Longitude)
    }
WiFi
import "github.com/AndroidGoLab/jni/net/wifi"

    mgr, _ := wifi.NewManager(ctx)
    defer mgr.Close()

    fmt.Println("WiFi enabled:", mgr.IsEnabled())
    info, _ := mgr.GetConnectionInfo()
    fmt.Println("SSID:", info.SSID)
Toast
import "github.com/AndroidGoLab/jni/widget/toast"

    toast.Show(ctx, "Hello from Go!", toast.LengthShort)

More examples: examples/

Supported Packages

53 Android API packages organized in a Java SDK-mirroring hierarchy:

Android API Go Package Import Path
Application Framework
app app github.com/AndroidGoLab/jni/app
alarm alarm github.com/AndroidGoLab/jni/app/alarm
download download github.com/AndroidGoLab/jni/app/download
job job github.com/AndroidGoLab/jni/app/job
notification notification github.com/AndroidGoLab/jni/app/notification
usage usage github.com/AndroidGoLab/jni/app/usage
accounts accounts github.com/AndroidGoLab/jni/accounts
Bluetooth
bluetooth bluetooth github.com/AndroidGoLab/jni/bluetooth
Content & Storage
clipboard clipboard github.com/AndroidGoLab/jni/content/clipboard
pm pm github.com/AndroidGoLab/jni/content/pm
preferences preferences github.com/AndroidGoLab/jni/content/preferences
resolver resolver github.com/AndroidGoLab/jni/content/resolver
permission permission github.com/AndroidGoLab/jni/content/permission
Graphics
pdf pdf github.com/AndroidGoLab/jni/graphics/pdf
Hardware
biometric biometric github.com/AndroidGoLab/jni/hardware/biometric
camera camera github.com/AndroidGoLab/jni/hardware/camera
ir ir github.com/AndroidGoLab/jni/hardware/ir
lights lights github.com/AndroidGoLab/jni/hardware/lights
usb usb github.com/AndroidGoLab/jni/hardware/usb
Health
health connect github.com/AndroidGoLab/jni/health/connect
Location
location location github.com/AndroidGoLab/jni/location
Media
audiomanager audiomanager github.com/AndroidGoLab/jni/media/audiomanager
player player github.com/AndroidGoLab/jni/media/player
projection projection github.com/AndroidGoLab/jni/media/projection
recorder recorder github.com/AndroidGoLab/jni/media/recorder
session session github.com/AndroidGoLab/jni/media/session
Networking
net net github.com/AndroidGoLab/jni/net
nsd nsd github.com/AndroidGoLab/jni/net/nsd
wifi wifi github.com/AndroidGoLab/jni/net/wifi
p2p p2p github.com/AndroidGoLab/jni/net/wifi/p2p
rtt rtt github.com/AndroidGoLab/jni/net/wifi/rtt
NFC
nfc nfc github.com/AndroidGoLab/jni/nfc
OS Services
battery battery github.com/AndroidGoLab/jni/os/battery
build build github.com/AndroidGoLab/jni/os/build
environment environment github.com/AndroidGoLab/jni/os/environment
keyguard keyguard github.com/AndroidGoLab/jni/os/keyguard
power power github.com/AndroidGoLab/jni/os/power
storage storage github.com/AndroidGoLab/jni/os/storage
vibrator vibrator github.com/AndroidGoLab/jni/os/vibrator
Providers
documents documents github.com/AndroidGoLab/jni/provider/documents
mediastore media github.com/AndroidGoLab/jni/provider/media
settings settings github.com/AndroidGoLab/jni/provider/settings
Security
keystore keystore github.com/AndroidGoLab/jni/security/keystore
credentials credentials github.com/AndroidGoLab/jni/credentials
omapi omapi github.com/AndroidGoLab/jni/se/omapi
Telecom
telecom telecom github.com/AndroidGoLab/jni/telecom
telephony telephony github.com/AndroidGoLab/jni/telephony
UI
display display github.com/AndroidGoLab/jni/view/display
inputmethod inputmethod github.com/AndroidGoLab/jni/view/inputmethod
toast toast github.com/AndroidGoLab/jni/widget/toast
Other
companion companion github.com/AndroidGoLab/jni/companion
print print github.com/AndroidGoLab/jni/print
speech speech github.com/AndroidGoLab/jni/speech

Architecture

The project converts Android Java API specifications into safe, idiomatic Go packages through four code generation stages:

flowchart TD
    JNISPEC["spec/jni.yaml"]
    JNIOVER["spec/overlays/jni.yaml"]
    JNITMPL["templates/jni/"]
    JAVASPEC["spec/java/*.yaml"]
    JAVAOVER["spec/overlays/java/*.yaml"]
    JAVATMPL["templates/java/"]
    CAPI["capi/*.go"]
    ROOT["*.go (VM, Env, Class, Object, ...)"]
    PKGS["{package}/*.go (53 packages)"]
    PROTO["proto/*/*.proto"]
    GRPC["grpc/server/ + grpc/client/"]

    JNISPEC --> S1
    JNIOVER --> S1
    JNITMPL --> S1
    subgraph S1["jnigen"]
        direction LR
        S1D["Generates CGo bindings + idiomatic JNI types"]
    end
    S1 --> CAPI
    S1 --> ROOT

    JAVASPEC --> S2
    JAVAOVER --> S2
    JAVATMPL --> S2
    subgraph S2["javagen"]
        direction LR
        S2D["Generates Android API wrapper packages"]
    end
    S2 --> PKGS

    JAVASPEC --> S3
    JAVAOVER --> S3
    subgraph S3["protogen + grpcgen"]
        direction LR
        S3D["Generates .proto files + gRPC server/client"]
    end
    S3 --> PROTO
    S3 --> GRPC

    style JNISPEC fill:#fff3cd,color:#000
    style JNIOVER fill:#fff3cd,color:#000
    style JNITMPL fill:#fff3cd,color:#000
    style JAVASPEC fill:#fff3cd,color:#000
    style JAVAOVER fill:#fff3cd,color:#000
    style JAVATMPL fill:#fff3cd,color:#000
    style CAPI fill:#d4edda,color:#000
    style ROOT fill:#cce5ff,color:#000
    style PKGS fill:#cce5ff,color:#000
    style PROTO fill:#d4edda,color:#000
    style GRPC fill:#d4edda,color:#000

Legend: Yellow = hand-written inputs, Green = generated intermediates, Blue = final consumer-facing output.

Layers
  1. Raw CGo Layer (capi/) — Direct C bindings to JNI via vtable dispatch. Generated by jnigen.

  2. 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.

  3. 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.

  4. gRPC Layer — See jni-proxy for the gRPC remote access layer.

Project Layout

.
├── *.go                          # Core JNI types (VM, Env, Class, Object, ...)
├── capi/                         # Raw CGo bindings to JNI C API
├── internal/                     # Internal: exception handling, test JVM
│
├── app/                          # Android API wrappers (Java SDK hierarchy)
│   ├── alarm/, download/, ...
├── bluetooth/
├── hardware/
│   ├── camera/, usb/, ...
├── media/
│   ├── audiomanager/, player/, ...
├── net/
│   ├── wifi/, nsd/, ...
├── os/
│   ├── power/, battery/, ...
├── ...                           # (53 packages total)
│
├── tools/                        # Code generators
│   ├── jnigen/                   #   Core JNI + capi generation
│   ├── javagen/                  #   Android API package generation
│   ├── protogen/                 #   .proto file generation
│   └── grpcgen/                  #   gRPC server/client generation
├── spec/                         # YAML API specifications
│   ├── jni.yaml                  #   JNI C API spec
│   ├── java/                     #   Per-package Android API specs
│   └── overlays/                 #   Hand-written customizations
├── templates/                    # Go text templates for code generation
│   ├── jni/
│   └── java/
│
├── ref/android/                  # Reference .class files
└── examples/                     # Per-package usage examples

Make Targets

Target Description Requires
make generate Run all generators JDK + protoc
make jni Generate core JNI + capi JDK
make java Generate Android API packages --
make proto Generate .proto files --
make protoc Compile .proto to Go stubs protoc + protoc-gen-go
make grpc Generate gRPC server/client protoc
make cli Generate jnicli cobra commands protoc
make test Run all tests JDK
make test-tools Run generator tests only --
make build Cross-compile for android/arm64 Android NDK
make lint Run golangci-lint golangci-lint
make clean Remove all generated files --

E2E Test Verification

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

  1. Create spec/java/{package}.yaml with the Java class, methods, and go_import path.
  2. Optionally create spec/overlays/java/{package}.yaml for customizations (extra methods, type overrides, name overrides).
  3. Run make java to generate the Go package.
  4. For gRPC support, see jni-proxy.

Documentation ¶

Overview ¶

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`.

Index ¶

Constants ¶

View Source
const (
	JNI_VERSION_1_1 = capi.JNI_VERSION_1_1
	JNI_VERSION_1_2 = capi.JNI_VERSION_1_2
	JNI_VERSION_1_4 = capi.JNI_VERSION_1_4
	JNI_VERSION_1_6 = capi.JNI_VERSION_1_6
	JNI_VERSION_1_8 = capi.JNI_VERSION_1_8
	JNI_VERSION_9   = capi.JNI_VERSION_9
	JNI_VERSION_10  = capi.JNI_VERSION_10
	JNI_VERSION_19  = capi.JNI_VERSION_19
	JNI_VERSION_20  = capi.JNI_VERSION_20
	JNI_VERSION_21  = capi.JNI_VERSION_21
)

JNI version constants.

View Source
const (
	JNI_FALSE = capi.JNI_FALSE
	JNI_TRUE  = capi.JNI_TRUE
)

JNI boolean constants.

View Source
const (
	JNI_COMMIT = capi.JNI_COMMIT
	JNI_ABORT  = capi.JNI_ABORT
)

JNI array release mode constants.

View Source
const (
	JNIInvalidRefType    = capi.JNIInvalidRefType
	JNILocalRefType      = capi.JNILocalRefType
	JNIGlobalRefType     = capi.JNIGlobalRefType
	JNIWeakGlobalRefType = capi.JNIWeakGlobalRefType
)

JNI object reference type constants.

View Source
const (
	JNI_OK        = Error(0)
	JNI_ERR       = Error(-1)
	JNI_EDETACHED = Error(-2)
	JNI_EVERSION  = Error(-3)
	JNI_ENOMEM    = Error(-4)
	JNI_EEXIST    = Error(-5)
	JNI_EINVAL    = Error(-6)
)

JNI error constants.

Variables ¶

View Source
var ErrDetached = Error(JNI_EDETACHED)

ErrDetached is returned by VM.GetEnv when the current thread is not attached to the JVM.

Functions ¶

func EnsureProxyInit ¶

func EnsureProxyInit(env *Env) error

EnsureProxyInit performs one-time initialization of the proxy infrastructure (native method registration for GoInvocationHandler and GoAbstractDispatch). Safe to call multiple times.

func RegisterProxyHandler ¶

func RegisterProxyHandler(h ProxyHandler) int64

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.

func SetProxyClassLoader ¶

func SetProxyClassLoader(cl *Object)

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).

func UnregisterProxyHandler ¶

func UnregisterProxyHandler(id int64)

UnregisterProxyHandler removes a handler by ID from the global registry.

Types ¶

type Array ¶

type Array struct {
	Object
}

Array wraps the JNI jarray reference type.

type BooleanArray ¶

type BooleanArray struct {
	Array
}

BooleanArray wraps the JNI jbooleanArray reference type.

type ByteArray ¶

type ByteArray struct {
	Array
}

ByteArray wraps the JNI jbyteArray reference type.

type CAPIObject ¶

type CAPIObject = capi.Object

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.

type CharArray ¶

type CharArray struct {
	Array
}

CharArray wraps the JNI jcharArray reference type.

type Class ¶

type Class struct {
	Object
}

Class wraps the JNI jclass reference type.

type DoubleArray ¶

type DoubleArray struct {
	Array
}

DoubleArray wraps the JNI jdoubleArray reference type.

type Env ¶

type Env struct {
	// contains filtered or unexported fields
}

Env wraps a JNIEnv pointer. It is only valid on the OS thread where it was obtained. Use VM.Do() to get a valid Env.

func EnvFromPtr ¶

func EnvFromPtr(ptr unsafe.Pointer) *Env

EnvFromPtr creates an Env from a raw JNIEnv pointer.

func (*Env) AllocObject ¶

func (e *Env) AllocObject(cls *Class) (*Object, error)

AllocObject wraps the JNI AllocObject function.

func (*Env) CallBooleanMethod ¶

func (e *Env) CallBooleanMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (uint8, error)

CallBooleanMethod wraps the JNI CallBooleanMethodA function.

func (*Env) CallByteMethod ¶

func (e *Env) CallByteMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (int8, error)

CallByteMethod wraps the JNI CallByteMethodA function.

func (*Env) CallCharMethod ¶

func (e *Env) CallCharMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (uint16, error)

CallCharMethod wraps the JNI CallCharMethodA function.

func (*Env) CallDoubleMethod ¶

func (e *Env) CallDoubleMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (float64, error)

CallDoubleMethod wraps the JNI CallDoubleMethodA function.

func (*Env) CallFloatMethod ¶

func (e *Env) CallFloatMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (float32, error)

CallFloatMethod wraps the JNI CallFloatMethodA function.

func (*Env) CallIntMethod ¶

func (e *Env) CallIntMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (int32, error)

CallIntMethod wraps the JNI CallIntMethodA function.

func (*Env) CallLongMethod ¶

func (e *Env) CallLongMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (int64, error)

CallLongMethod wraps the JNI CallLongMethodA function.

func (*Env) CallNonvirtualBooleanMethod ¶

func (e *Env) CallNonvirtualBooleanMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (uint8, error)

CallNonvirtualBooleanMethod wraps the JNI CallNonvirtualBooleanMethodA function.

func (*Env) CallNonvirtualByteMethod ¶

func (e *Env) CallNonvirtualByteMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (int8, error)

CallNonvirtualByteMethod wraps the JNI CallNonvirtualByteMethodA function.

func (*Env) CallNonvirtualCharMethod ¶

func (e *Env) CallNonvirtualCharMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (uint16, error)

CallNonvirtualCharMethod wraps the JNI CallNonvirtualCharMethodA function.

func (*Env) CallNonvirtualDoubleMethod ¶

func (e *Env) CallNonvirtualDoubleMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (float64, error)

CallNonvirtualDoubleMethod wraps the JNI CallNonvirtualDoubleMethodA function.

func (*Env) CallNonvirtualFloatMethod ¶

func (e *Env) CallNonvirtualFloatMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (float32, error)

CallNonvirtualFloatMethod wraps the JNI CallNonvirtualFloatMethodA function.

func (*Env) CallNonvirtualIntMethod ¶

func (e *Env) CallNonvirtualIntMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (int32, error)

CallNonvirtualIntMethod wraps the JNI CallNonvirtualIntMethodA function.

func (*Env) CallNonvirtualLongMethod ¶

func (e *Env) CallNonvirtualLongMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (int64, error)

CallNonvirtualLongMethod wraps the JNI CallNonvirtualLongMethodA function.

func (*Env) CallNonvirtualObjectMethod ¶

func (e *Env) CallNonvirtualObjectMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (*Object, error)

CallNonvirtualObjectMethod wraps the JNI CallNonvirtualObjectMethodA function.

func (*Env) CallNonvirtualShortMethod ¶

func (e *Env) CallNonvirtualShortMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) (int16, error)

CallNonvirtualShortMethod wraps the JNI CallNonvirtualShortMethodA function.

func (*Env) CallNonvirtualVoidMethod ¶

func (e *Env) CallNonvirtualVoidMethod(
	obj *Object,
	cls *Class,
	method MethodID,
	args ...Value,
) error

CallNonvirtualVoidMethod wraps the JNI CallNonvirtualVoidMethodA function.

func (*Env) CallObjectMethod ¶

func (e *Env) CallObjectMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (*Object, error)

CallObjectMethod wraps the JNI CallObjectMethodA function.

func (*Env) CallShortMethod ¶

func (e *Env) CallShortMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) (int16, error)

CallShortMethod wraps the JNI CallShortMethodA function.

func (*Env) CallStaticBooleanMethod ¶

func (e *Env) CallStaticBooleanMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (uint8, error)

CallStaticBooleanMethod wraps the JNI CallStaticBooleanMethodA function.

func (*Env) CallStaticByteMethod ¶

func (e *Env) CallStaticByteMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (int8, error)

CallStaticByteMethod wraps the JNI CallStaticByteMethodA function.

func (*Env) CallStaticCharMethod ¶

func (e *Env) CallStaticCharMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (uint16, error)

CallStaticCharMethod wraps the JNI CallStaticCharMethodA function.

func (*Env) CallStaticDoubleMethod ¶

func (e *Env) CallStaticDoubleMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (float64, error)

CallStaticDoubleMethod wraps the JNI CallStaticDoubleMethodA function.

func (*Env) CallStaticFloatMethod ¶

func (e *Env) CallStaticFloatMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (float32, error)

CallStaticFloatMethod wraps the JNI CallStaticFloatMethodA function.

func (*Env) CallStaticIntMethod ¶

func (e *Env) CallStaticIntMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (int32, error)

CallStaticIntMethod wraps the JNI CallStaticIntMethodA function.

func (*Env) CallStaticLongMethod ¶

func (e *Env) CallStaticLongMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (int64, error)

CallStaticLongMethod wraps the JNI CallStaticLongMethodA function.

func (*Env) CallStaticObjectMethod ¶

func (e *Env) CallStaticObjectMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (*Object, error)

CallStaticObjectMethod wraps the JNI CallStaticObjectMethodA function.

func (*Env) CallStaticShortMethod ¶

func (e *Env) CallStaticShortMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) (int16, error)

CallStaticShortMethod wraps the JNI CallStaticShortMethodA function.

func (*Env) CallStaticVoidMethod ¶

func (e *Env) CallStaticVoidMethod(
	cls *Class,
	method MethodID,
	args ...Value,
) error

CallStaticVoidMethod wraps the JNI CallStaticVoidMethodA function.

func (*Env) CallVoidMethod ¶

func (e *Env) CallVoidMethod(
	obj *Object,
	method MethodID,
	args ...Value,
) error

CallVoidMethod wraps the JNI CallVoidMethodA function.

func (*Env) DefineClass ¶

func (e *Env) DefineClass(
	name string,
	loader *Object,
	buf []byte,
) (*Class, error)

DefineClass wraps the JNI DefineClass function.

func (*Env) DeleteGlobalRef ¶

func (e *Env) DeleteGlobalRef(globalRef *Object)

DeleteGlobalRef wraps the JNI DeleteGlobalRef function.

func (*Env) DeleteLocalRef ¶

func (e *Env) DeleteLocalRef(localRef *Object)

DeleteLocalRef wraps the JNI DeleteLocalRef function.

func (*Env) DeleteWeakGlobalRef ¶

func (e *Env) DeleteWeakGlobalRef(ref *WeakRef)

DeleteWeakGlobalRef wraps the JNI DeleteWeakGlobalRef function.

func (*Env) EnsureLocalCapacity ¶

func (e *Env) EnsureLocalCapacity(capacity int32) error

EnsureLocalCapacity wraps the JNI EnsureLocalCapacity function.

func (*Env) ExceptionCheck ¶

func (e *Env) ExceptionCheck() bool

ExceptionCheck wraps the JNI ExceptionCheck function.

func (*Env) ExceptionClear ¶

func (e *Env) ExceptionClear()

ExceptionClear wraps the JNI ExceptionClear function.

func (*Env) ExceptionDescribe ¶

func (e *Env) ExceptionDescribe()

ExceptionDescribe wraps the JNI ExceptionDescribe function.

func (*Env) ExceptionOccurred ¶

func (e *Env) ExceptionOccurred() *Throwable

ExceptionOccurred wraps the JNI ExceptionOccurred function.

func (*Env) FatalError ¶

func (e *Env) FatalError(msg string)

FatalError wraps the JNI FatalError function.

func (*Env) FindClass ¶

func (e *Env) FindClass(name string) (*Class, error)

FindClass wraps the JNI FindClass function.

func (*Env) FromReflectedField ¶

func (e *Env) FromReflectedField(field *Object) FieldID

FromReflectedField wraps the JNI FromReflectedField function.

func (*Env) FromReflectedMethod ¶

func (e *Env) FromReflectedMethod(method *Object) MethodID

FromReflectedMethod wraps the JNI FromReflectedMethod function.

func (*Env) GetArrayLength ¶

func (e *Env) GetArrayLength(array *Array) int32

GetArrayLength wraps the JNI GetArrayLength function.

func (*Env) GetBooleanArrayElements ¶

func (e *Env) GetBooleanArrayElements(array *BooleanArray, isCopy *uint8) unsafe.Pointer

GetBooleanArrayElements wraps the JNI GetBooleanArrayElements function.

func (*Env) GetBooleanArrayRegion ¶

func (e *Env) GetBooleanArrayRegion(
	array *BooleanArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetBooleanArrayRegion wraps the JNI GetBooleanArrayRegion function.

func (*Env) GetBooleanField ¶

func (e *Env) GetBooleanField(obj *Object, field FieldID) uint8

GetBooleanField wraps the JNI GetBooleanField function.

func (*Env) GetByteArrayElements ¶

func (e *Env) GetByteArrayElements(array *ByteArray, isCopy *uint8) unsafe.Pointer

GetByteArrayElements wraps the JNI GetByteArrayElements function.

func (*Env) GetByteArrayRegion ¶

func (e *Env) GetByteArrayRegion(
	array *ByteArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetByteArrayRegion wraps the JNI GetByteArrayRegion function.

func (*Env) GetByteField ¶

func (e *Env) GetByteField(obj *Object, field FieldID) int8

GetByteField wraps the JNI GetByteField function.

func (*Env) GetCharArrayElements ¶

func (e *Env) GetCharArrayElements(array *CharArray, isCopy *uint8) unsafe.Pointer

GetCharArrayElements wraps the JNI GetCharArrayElements function.

func (*Env) GetCharArrayRegion ¶

func (e *Env) GetCharArrayRegion(
	array *CharArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetCharArrayRegion wraps the JNI GetCharArrayRegion function.

func (*Env) GetCharField ¶

func (e *Env) GetCharField(obj *Object, field FieldID) uint16

GetCharField wraps the JNI GetCharField function.

func (*Env) GetDirectBufferAddress ¶

func (e *Env) GetDirectBufferAddress(buf *Object) unsafe.Pointer

GetDirectBufferAddress wraps the JNI GetDirectBufferAddress function.

func (*Env) GetDirectBufferCapacity ¶

func (e *Env) GetDirectBufferCapacity(buf *Object) int64

GetDirectBufferCapacity wraps the JNI GetDirectBufferCapacity function.

func (*Env) GetDoubleArrayElements ¶

func (e *Env) GetDoubleArrayElements(array *DoubleArray, isCopy *uint8) unsafe.Pointer

GetDoubleArrayElements wraps the JNI GetDoubleArrayElements function.

func (*Env) GetDoubleArrayRegion ¶

func (e *Env) GetDoubleArrayRegion(
	array *DoubleArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetDoubleArrayRegion wraps the JNI GetDoubleArrayRegion function.

func (*Env) GetDoubleField ¶

func (e *Env) GetDoubleField(obj *Object, field FieldID) float64

GetDoubleField wraps the JNI GetDoubleField function.

func (*Env) GetFieldID ¶

func (e *Env) GetFieldID(
	cls *Class,
	name string,
	sig string,
) (FieldID, error)

GetFieldID wraps the JNI GetFieldID function.

func (*Env) GetFloatArrayElements ¶

func (e *Env) GetFloatArrayElements(array *FloatArray, isCopy *uint8) unsafe.Pointer

GetFloatArrayElements wraps the JNI GetFloatArrayElements function.

func (*Env) GetFloatArrayRegion ¶

func (e *Env) GetFloatArrayRegion(
	array *FloatArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetFloatArrayRegion wraps the JNI GetFloatArrayRegion function.

func (*Env) GetFloatField ¶

func (e *Env) GetFloatField(obj *Object, field FieldID) float32

GetFloatField wraps the JNI GetFloatField function.

func (*Env) GetIntArrayElements ¶

func (e *Env) GetIntArrayElements(array *IntArray, isCopy *uint8) unsafe.Pointer

GetIntArrayElements wraps the JNI GetIntArrayElements function.

func (*Env) GetIntArrayRegion ¶

func (e *Env) GetIntArrayRegion(
	array *IntArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetIntArrayRegion wraps the JNI GetIntArrayRegion function.

func (*Env) GetIntField ¶

func (e *Env) GetIntField(obj *Object, field FieldID) int32

GetIntField wraps the JNI GetIntField function.

func (*Env) GetLongArrayElements ¶

func (e *Env) GetLongArrayElements(array *LongArray, isCopy *uint8) unsafe.Pointer

GetLongArrayElements wraps the JNI GetLongArrayElements function.

func (*Env) GetLongArrayRegion ¶

func (e *Env) GetLongArrayRegion(
	array *LongArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetLongArrayRegion wraps the JNI GetLongArrayRegion function.

func (*Env) GetLongField ¶

func (e *Env) GetLongField(obj *Object, field FieldID) int64

GetLongField wraps the JNI GetLongField function.

func (*Env) GetMethodID ¶

func (e *Env) GetMethodID(
	cls *Class,
	name string,
	sig string,
) (MethodID, error)

GetMethodID wraps the JNI GetMethodID function.

func (*Env) GetObjectArrayElement ¶

func (e *Env) GetObjectArrayElement(array *ObjectArray, index int32) (*Object, error)

GetObjectArrayElement wraps the JNI GetObjectArrayElement function.

func (*Env) GetObjectClass ¶

func (e *Env) GetObjectClass(obj *Object) *Class

GetObjectClass wraps the JNI GetObjectClass function.

func (*Env) GetObjectField ¶

func (e *Env) GetObjectField(obj *Object, field FieldID) *Object

GetObjectField wraps the JNI GetObjectField function.

func (*Env) GetObjectRefType ¶

func (e *Env) GetObjectRefType(obj *Object) ObjectRefType

GetObjectRefType wraps the JNI GetObjectRefType function.

func (*Env) GetPrimitiveArrayCritical ¶

func (e *Env) GetPrimitiveArrayCritical(array *Array, isCopy *uint8) unsafe.Pointer

GetPrimitiveArrayCritical wraps the JNI GetPrimitiveArrayCritical function.

func (*Env) GetShortArrayElements ¶

func (e *Env) GetShortArrayElements(array *ShortArray, isCopy *uint8) unsafe.Pointer

GetShortArrayElements wraps the JNI GetShortArrayElements function.

func (*Env) GetShortArrayRegion ¶

func (e *Env) GetShortArrayRegion(
	array *ShortArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

GetShortArrayRegion wraps the JNI GetShortArrayRegion function.

func (*Env) GetShortField ¶

func (e *Env) GetShortField(obj *Object, field FieldID) int16

GetShortField wraps the JNI GetShortField function.

func (*Env) GetStaticBooleanField ¶

func (e *Env) GetStaticBooleanField(cls *Class, field FieldID) uint8

GetStaticBooleanField wraps the JNI GetStaticBooleanField function.

func (*Env) GetStaticByteField ¶

func (e *Env) GetStaticByteField(cls *Class, field FieldID) int8

GetStaticByteField wraps the JNI GetStaticByteField function.

func (*Env) GetStaticCharField ¶

func (e *Env) GetStaticCharField(cls *Class, field FieldID) uint16

GetStaticCharField wraps the JNI GetStaticCharField function.

func (*Env) GetStaticDoubleField ¶

func (e *Env) GetStaticDoubleField(cls *Class, field FieldID) float64

GetStaticDoubleField wraps the JNI GetStaticDoubleField function.

func (*Env) GetStaticFieldID ¶

func (e *Env) GetStaticFieldID(
	cls *Class,
	name string,
	sig string,
) (FieldID, error)

GetStaticFieldID wraps the JNI GetStaticFieldID function.

func (*Env) GetStaticFloatField ¶

func (e *Env) GetStaticFloatField(cls *Class, field FieldID) float32

GetStaticFloatField wraps the JNI GetStaticFloatField function.

func (*Env) GetStaticIntField ¶

func (e *Env) GetStaticIntField(cls *Class, field FieldID) int32

GetStaticIntField wraps the JNI GetStaticIntField function.

func (*Env) GetStaticLongField ¶

func (e *Env) GetStaticLongField(cls *Class, field FieldID) int64

GetStaticLongField wraps the JNI GetStaticLongField function.

func (*Env) GetStaticMethodID ¶

func (e *Env) GetStaticMethodID(
	cls *Class,
	name string,
	sig string,
) (MethodID, error)

GetStaticMethodID wraps the JNI GetStaticMethodID function.

func (*Env) GetStaticObjectField ¶

func (e *Env) GetStaticObjectField(cls *Class, field FieldID) *Object

GetStaticObjectField wraps the JNI GetStaticObjectField function.

func (*Env) GetStaticShortField ¶

func (e *Env) GetStaticShortField(cls *Class, field FieldID) int16

GetStaticShortField wraps the JNI GetStaticShortField function.

func (*Env) GetStringChars ¶

func (e *Env) GetStringChars(str *String, isCopy *uint8) (unsafe.Pointer, error)

GetStringChars wraps the JNI GetStringChars function.

func (*Env) GetStringCritical ¶

func (e *Env) GetStringCritical(str *String, isCopy *uint8) unsafe.Pointer

GetStringCritical wraps the JNI GetStringCritical function.

func (*Env) GetStringLength ¶

func (e *Env) GetStringLength(str *String) int32

GetStringLength wraps the JNI GetStringLength function.

func (*Env) GetStringRegion ¶

func (e *Env) GetStringRegion(
	str *String,
	start int32,
	len int32,
	buf []uint16,
) error

GetStringRegion wraps the JNI GetStringRegion function.

func (*Env) GetStringUTFChars ¶

func (e *Env) GetStringUTFChars(str *String, isCopy *uint8) (unsafe.Pointer, error)

GetStringUTFChars wraps the JNI GetStringUTFChars function.

func (*Env) GetStringUTFLength ¶

func (e *Env) GetStringUTFLength(str *String) int32

GetStringUTFLength wraps the JNI GetStringUTFLength function.

func (*Env) GetStringUTFRegion ¶

func (e *Env) GetStringUTFRegion(
	str *String,
	start int32,
	len int32,
	buf []byte,
) error

GetStringUTFRegion wraps the JNI GetStringUTFRegion function.

func (*Env) GetSuperclass ¶

func (e *Env) GetSuperclass(cls *Class) *Class

GetSuperclass wraps the JNI GetSuperclass function.

func (*Env) GetVersion ¶

func (e *Env) GetVersion() int32

GetVersion wraps the JNI GetVersion function.

func (*Env) GoString ¶

func (e *Env) GoString(str *String) string

GoString converts a JNI String to a Go string using modified UTF-8 encoding. If str is nil, it returns an empty string.

func (*Env) IsAssignableFrom ¶

func (e *Env) IsAssignableFrom(cls1 *Class, cls2 *Class) bool

IsAssignableFrom wraps the JNI IsAssignableFrom function.

func (*Env) IsInstanceOf ¶

func (e *Env) IsInstanceOf(obj *Object, cls *Class) bool

IsInstanceOf wraps the JNI IsInstanceOf function.

func (*Env) IsSameObject ¶

func (e *Env) IsSameObject(ref1 *Object, ref2 *Object) bool

IsSameObject wraps the JNI IsSameObject function.

func (*Env) MonitorEnter ¶

func (e *Env) MonitorEnter(obj *Object) error

MonitorEnter wraps the JNI MonitorEnter function.

func (*Env) MonitorExit ¶

func (e *Env) MonitorExit(obj *Object) error

MonitorExit wraps the JNI MonitorExit function.

func (*Env) NewBooleanArray ¶

func (e *Env) NewBooleanArray(length int32) *BooleanArray

NewBooleanArray wraps the JNI NewBooleanArray function.

func (*Env) NewByteArray ¶

func (e *Env) NewByteArray(length int32) *ByteArray

NewByteArray wraps the JNI NewByteArray function.

func (*Env) NewCharArray ¶

func (e *Env) NewCharArray(length int32) *CharArray

NewCharArray wraps the JNI NewCharArray function.

func (*Env) NewDirectByteBuffer ¶

func (e *Env) NewDirectByteBuffer(address unsafe.Pointer, capacity int64) *Object

NewDirectByteBuffer wraps the JNI NewDirectByteBuffer function.

func (*Env) NewDoubleArray ¶

func (e *Env) NewDoubleArray(length int32) *DoubleArray

NewDoubleArray wraps the JNI NewDoubleArray function.

func (*Env) NewFloatArray ¶

func (e *Env) NewFloatArray(length int32) *FloatArray

NewFloatArray wraps the JNI NewFloatArray function.

func (*Env) NewGlobalRef ¶

func (e *Env) NewGlobalRef(obj *Object) *Object

NewGlobalRef wraps the JNI NewGlobalRef function.

func (*Env) NewIntArray ¶

func (e *Env) NewIntArray(length int32) *IntArray

NewIntArray wraps the JNI NewIntArray function.

func (*Env) NewLocalRef ¶

func (e *Env) NewLocalRef(obj *Object) *Object

NewLocalRef wraps the JNI NewLocalRef function.

func (*Env) NewLongArray ¶

func (e *Env) NewLongArray(length int32) *LongArray

NewLongArray wraps the JNI NewLongArray function.

func (*Env) NewObject ¶

func (e *Env) NewObject(
	cls *Class,
	method MethodID,
	args ...Value,
) (*Object, error)

NewObject wraps the JNI NewObjectA function.

func (*Env) NewObjectArray ¶

func (e *Env) NewObjectArray(
	length int32,
	elementClass *Class,
	initialElement *Object,
) (*ObjectArray, error)

NewObjectArray wraps the JNI NewObjectArray function.

func (*Env) NewProxy ¶

func (e *Env) NewProxy(
	ifaces []*Class,
	handler func(env *Env, methodName string, args []*Object) (*Object, error),
) (proxy *Object, cleanup func(), err error)

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.

Example:

proxy, cleanup, err := env.NewProxy(
    []*Class{listenerClass},
    func(env *Env, method string, args []*Object) (*Object, error) {
        switch method {
        case "onLocationChanged":
            // handle location update
        }
        return nil, nil
    },
)
defer cleanup()

func (*Env) NewProxyFull ¶

func (e *Env) NewProxyFull(
	ifaces []*Class,
	handler ProxyHandlerFull,
) (proxy *Object, cleanup func(), err error)

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.

func (*Env) NewShortArray ¶

func (e *Env) NewShortArray(length int32) *ShortArray

NewShortArray wraps the JNI NewShortArray function.

func (*Env) NewString ¶

func (e *Env) NewString(unicodeChars []uint16) (*String, error)

NewString wraps the JNI NewString function.

func (*Env) NewStringUTF ¶

func (e *Env) NewStringUTF(bytes string) (*String, error)

NewStringUTF wraps the JNI NewStringUTF function.

func (*Env) NewWeakGlobalRef ¶

func (e *Env) NewWeakGlobalRef(obj *Object) *WeakRef

NewWeakGlobalRef wraps the JNI NewWeakGlobalRef function.

func (*Env) PopLocalFrame ¶

func (e *Env) PopLocalFrame(result *Object) *Object

PopLocalFrame wraps the JNI PopLocalFrame function.

func (*Env) Ptr ¶

func (e *Env) Ptr() unsafe.Pointer

Ptr returns the raw JNIEnv pointer for interop with other CGo code.

func (*Env) PushLocalFrame ¶

func (e *Env) PushLocalFrame(capacity int32) error

PushLocalFrame wraps the JNI PushLocalFrame function.

func (*Env) RegisterNatives ¶

func (e *Env) RegisterNatives(
	cls *Class,
	methods unsafe.Pointer,
	nMethods int32,
) error

RegisterNatives wraps the JNI RegisterNatives function.

func (*Env) ReleaseBooleanArrayElements ¶

func (e *Env) ReleaseBooleanArrayElements(
	array *BooleanArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseBooleanArrayElements wraps the JNI ReleaseBooleanArrayElements function.

func (*Env) ReleaseByteArrayElements ¶

func (e *Env) ReleaseByteArrayElements(
	array *ByteArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseByteArrayElements wraps the JNI ReleaseByteArrayElements function.

func (*Env) ReleaseCharArrayElements ¶

func (e *Env) ReleaseCharArrayElements(
	array *CharArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseCharArrayElements wraps the JNI ReleaseCharArrayElements function.

func (*Env) ReleaseDoubleArrayElements ¶

func (e *Env) ReleaseDoubleArrayElements(
	array *DoubleArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseDoubleArrayElements wraps the JNI ReleaseDoubleArrayElements function.

func (*Env) ReleaseFloatArrayElements ¶

func (e *Env) ReleaseFloatArrayElements(
	array *FloatArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseFloatArrayElements wraps the JNI ReleaseFloatArrayElements function.

func (*Env) ReleaseIntArrayElements ¶

func (e *Env) ReleaseIntArrayElements(
	array *IntArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseIntArrayElements wraps the JNI ReleaseIntArrayElements function.

func (*Env) ReleaseLongArrayElements ¶

func (e *Env) ReleaseLongArrayElements(
	array *LongArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseLongArrayElements wraps the JNI ReleaseLongArrayElements function.

func (*Env) ReleasePrimitiveArrayCritical ¶

func (e *Env) ReleasePrimitiveArrayCritical(
	array *Array,
	carray unsafe.Pointer,
	mode int32,
)

ReleasePrimitiveArrayCritical wraps the JNI ReleasePrimitiveArrayCritical function.

func (*Env) ReleaseShortArrayElements ¶

func (e *Env) ReleaseShortArrayElements(
	array *ShortArray,
	elems unsafe.Pointer,
	mode int32,
)

ReleaseShortArrayElements wraps the JNI ReleaseShortArrayElements function.

func (*Env) ReleaseStringChars ¶

func (e *Env) ReleaseStringChars(str *String, chars unsafe.Pointer)

ReleaseStringChars wraps the JNI ReleaseStringChars function.

func (*Env) ReleaseStringCritical ¶

func (e *Env) ReleaseStringCritical(str *String, cstr unsafe.Pointer)

ReleaseStringCritical wraps the JNI ReleaseStringCritical function.

func (*Env) ReleaseStringUTFChars ¶

func (e *Env) ReleaseStringUTFChars(str *String, utf unsafe.Pointer)

ReleaseStringUTFChars wraps the JNI ReleaseStringUTFChars function.

func (*Env) SetBooleanArrayRegion ¶

func (e *Env) SetBooleanArrayRegion(
	array *BooleanArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetBooleanArrayRegion wraps the JNI SetBooleanArrayRegion function.

func (*Env) SetBooleanField ¶

func (e *Env) SetBooleanField(
	obj *Object,
	field FieldID,
	value uint8,
)

SetBooleanField wraps the JNI SetBooleanField function.

func (*Env) SetByteArrayRegion ¶

func (e *Env) SetByteArrayRegion(
	array *ByteArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetByteArrayRegion wraps the JNI SetByteArrayRegion function.

func (*Env) SetByteField ¶

func (e *Env) SetByteField(
	obj *Object,
	field FieldID,
	value int8,
)

SetByteField wraps the JNI SetByteField function.

func (*Env) SetCharArrayRegion ¶

func (e *Env) SetCharArrayRegion(
	array *CharArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetCharArrayRegion wraps the JNI SetCharArrayRegion function.

func (*Env) SetCharField ¶

func (e *Env) SetCharField(
	obj *Object,
	field FieldID,
	value uint16,
)

SetCharField wraps the JNI SetCharField function.

func (*Env) SetDoubleArrayRegion ¶

func (e *Env) SetDoubleArrayRegion(
	array *DoubleArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetDoubleArrayRegion wraps the JNI SetDoubleArrayRegion function.

func (*Env) SetDoubleField ¶

func (e *Env) SetDoubleField(
	obj *Object,
	field FieldID,
	value float64,
)

SetDoubleField wraps the JNI SetDoubleField function.

func (*Env) SetFloatArrayRegion ¶

func (e *Env) SetFloatArrayRegion(
	array *FloatArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetFloatArrayRegion wraps the JNI SetFloatArrayRegion function.

func (*Env) SetFloatField ¶

func (e *Env) SetFloatField(
	obj *Object,
	field FieldID,
	value float32,
)

SetFloatField wraps the JNI SetFloatField function.

func (*Env) SetIntArrayRegion ¶

func (e *Env) SetIntArrayRegion(
	array *IntArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetIntArrayRegion wraps the JNI SetIntArrayRegion function.

func (*Env) SetIntField ¶

func (e *Env) SetIntField(
	obj *Object,
	field FieldID,
	value int32,
)

SetIntField wraps the JNI SetIntField function.

func (*Env) SetLongArrayRegion ¶

func (e *Env) SetLongArrayRegion(
	array *LongArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetLongArrayRegion wraps the JNI SetLongArrayRegion function.

func (*Env) SetLongField ¶

func (e *Env) SetLongField(
	obj *Object,
	field FieldID,
	value int64,
)

SetLongField wraps the JNI SetLongField function.

func (*Env) SetObjectArrayElement ¶

func (e *Env) SetObjectArrayElement(
	array *ObjectArray,
	index int32,
	value *Object,
) error

SetObjectArrayElement wraps the JNI SetObjectArrayElement function.

func (*Env) SetObjectField ¶

func (e *Env) SetObjectField(
	obj *Object,
	field FieldID,
	value *Object,
)

SetObjectField wraps the JNI SetObjectField function.

func (*Env) SetShortArrayRegion ¶

func (e *Env) SetShortArrayRegion(
	array *ShortArray,
	start int32,
	len int32,
	buf unsafe.Pointer,
)

SetShortArrayRegion wraps the JNI SetShortArrayRegion function.

func (*Env) SetShortField ¶

func (e *Env) SetShortField(
	obj *Object,
	field FieldID,
	value int16,
)

SetShortField wraps the JNI SetShortField function.

func (*Env) SetStaticBooleanField ¶

func (e *Env) SetStaticBooleanField(
	cls *Class,
	field FieldID,
	value uint8,
)

SetStaticBooleanField wraps the JNI SetStaticBooleanField function.

func (*Env) SetStaticByteField ¶

func (e *Env) SetStaticByteField(
	cls *Class,
	field FieldID,
	value int8,
)

SetStaticByteField wraps the JNI SetStaticByteField function.

func (*Env) SetStaticCharField ¶

func (e *Env) SetStaticCharField(
	cls *Class,
	field FieldID,
	value uint16,
)

SetStaticCharField wraps the JNI SetStaticCharField function.

func (*Env) SetStaticDoubleField ¶

func (e *Env) SetStaticDoubleField(
	cls *Class,
	field FieldID,
	value float64,
)

SetStaticDoubleField wraps the JNI SetStaticDoubleField function.

func (*Env) SetStaticFloatField ¶

func (e *Env) SetStaticFloatField(
	cls *Class,
	field FieldID,
	value float32,
)

SetStaticFloatField wraps the JNI SetStaticFloatField function.

func (*Env) SetStaticIntField ¶

func (e *Env) SetStaticIntField(
	cls *Class,
	field FieldID,
	value int32,
)

SetStaticIntField wraps the JNI SetStaticIntField function.

func (*Env) SetStaticLongField ¶

func (e *Env) SetStaticLongField(
	cls *Class,
	field FieldID,
	value int64,
)

SetStaticLongField wraps the JNI SetStaticLongField function.

func (*Env) SetStaticObjectField ¶

func (e *Env) SetStaticObjectField(
	cls *Class,
	field FieldID,
	value *Object,
)

SetStaticObjectField wraps the JNI SetStaticObjectField function.

func (*Env) SetStaticShortField ¶

func (e *Env) SetStaticShortField(
	cls *Class,
	field FieldID,
	value int16,
)

SetStaticShortField wraps the JNI SetStaticShortField function.

func (*Env) Throw ¶

func (e *Env) Throw(throwable *Throwable) error

Throw wraps the JNI Throw function.

func (*Env) ThrowNew ¶

func (e *Env) ThrowNew(cls *Class, message string) error

ThrowNew wraps the JNI ThrowNew function.

func (*Env) ToReflectedField ¶

func (e *Env) ToReflectedField(
	cls *Class,
	field FieldID,
	isStatic bool,
) *Object

ToReflectedField wraps the JNI ToReflectedField function.

func (*Env) ToReflectedMethod ¶

func (e *Env) ToReflectedMethod(
	cls *Class,
	method MethodID,
	isStatic bool,
) *Object

ToReflectedMethod wraps the JNI ToReflectedMethod function.

func (*Env) UnregisterNatives ¶

func (e *Env) UnregisterNatives(cls *Class) error

UnregisterNatives wraps the JNI UnregisterNatives function.

type Error ¶

type Error int32

Error represents a JNI return code error (JNI_ERR, JNI_EDETACHED, etc.).

func (Error) Error ¶

func (e Error) Error() string

type FieldID ¶

type FieldID = capi.JfieldID

FieldID is a JNI field identifier.

type FloatArray ¶

type FloatArray struct {
	Array
}

FloatArray wraps the JNI jfloatArray reference type.

type GlobalRef ¶

type GlobalRef = Object

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.

type IntArray ¶

type IntArray struct {
	Array
}

IntArray wraps the JNI jintArray reference type.

type LongArray ¶

type LongArray struct {
	Array
}

LongArray wraps the JNI jlongArray reference type.

type MethodID ¶

type MethodID = capi.JmethodID

MethodID is a JNI method identifier.

type Object ¶

type Object struct {
	// contains filtered or unexported fields
}

Object wraps the JNI jobject reference type.

func ObjectFromRef ¶

func ObjectFromRef(ref capi.Object) *Object

ObjectFromRef wraps a raw JNI jobject reference in an Object. The caller is responsible for ensuring the reference is valid.

func (*Object) Ref ¶

func (o *Object) Ref() capi.Object

Ref returns the underlying capi reference.

type ObjectArray ¶

type ObjectArray struct {
	Array
}

ObjectArray wraps the JNI jobjectArray reference type.

type ObjectRefType ¶

type ObjectRefType = capi.Jint

ObjectRefType represents the type of a JNI object reference.

type ProxyHandler ¶

type ProxyHandler func(env *Env, methodName string, args []*Object) (*Object, error)

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.

type ProxyHandlerFull ¶

type ProxyHandlerFull func(env *Env, method *Object, methodName string, args []*Object) (*Object, 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()).

type ShortArray ¶

type ShortArray struct {
	Array
}

ShortArray wraps the JNI jshortArray reference type.

type String ¶

type String struct {
	Object
}

String wraps the JNI jstring reference type.

type Throwable ¶

type Throwable struct {
	Object
}

Throwable wraps the JNI jthrowable reference type.

type VM ¶

type VM struct {
	// contains filtered or unexported fields
}

VM wraps a JNI JavaVM pointer. It is process-global and thread-safe.

func VMFromPtr ¶

func VMFromPtr(ptr unsafe.Pointer) *VM

VMFromPtr creates a VM from a raw JavaVM pointer.

func (*VM) AttachCurrentThread ¶

func (vm *VM) AttachCurrentThread() (*Env, error)

AttachCurrentThread attaches the current OS thread to the JVM and returns a valid JNIEnv pointer.

func (*VM) Do ¶

func (vm *VM) Do(fn func(env *Env) error) error

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:

  1. The goroutine stays on the same OS thread for the duration of fn.
  2. The OS thread has a valid JNIEnv (attaching if necessary).
  3. 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.

func (*VM) GetEnv ¶

func (vm *VM) GetEnv(version capi.Jint) (*Env, error)

GetEnv returns the JNIEnv for the current thread if it is already attached to the JVM. Returns ErrDetached if the thread is not attached.

func (*VM) Ptr ¶

func (vm *VM) Ptr() unsafe.Pointer

Ptr returns the raw JavaVM pointer for interop with other CGo code.

type Value ¶

type Value struct {
	// contains filtered or unexported fields
}

Value wraps a JNI jvalue union. Use the typed constructors (IntValue, LongValue, ObjectValue, etc.) to create values for method call arguments.

func BooleanValue ¶

func BooleanValue(v uint8) Value

BooleanValue creates a Value holding a uint8.

func ByteValue ¶

func ByteValue(v int8) Value

ByteValue creates a Value holding a int8.

func CharValue ¶

func CharValue(v uint16) Value

CharValue creates a Value holding a uint16.

func DoubleValue ¶

func DoubleValue(v float64) Value

DoubleValue creates a Value holding a float64.

func FloatValue ¶

func FloatValue(v float32) Value

FloatValue creates a Value holding a float32.

func IntValue ¶

func IntValue(v int32) Value

IntValue creates a Value holding a int32.

func LongValue ¶

func LongValue(v int64) Value

LongValue creates a Value holding a int64.

func ObjectValue ¶

func ObjectValue(v *Object) Value

ObjectValue creates a Value holding an Object reference.

func ShortValue ¶

func ShortValue(v int16) Value

ShortValue creates a Value holding a int16.

func (Value) Raw ¶

func (v Value) Raw() capi.Jvalue

Raw returns the underlying capi.Jvalue for interop.

type WeakRef ¶

type WeakRef struct {
	Object
}

WeakRef wraps the JNI jweak reference type.

Directories ¶

Path Synopsis
Package accounts provides Go bindings for android.accounts.
Package accounts provides Go bindings for android.accounts.
app
Package app provides Go bindings for android.os.
Package app provides Go bindings for android.os.
admin
Package admin provides Go bindings for android.app.admin.
Package admin provides Go bindings for android.app.admin.
alarm
Package alarm provides Go bindings for android.app.
Package alarm provides Go bindings for android.app.
blob
Package blob provides Go bindings for android.app.blob.
Package blob provides Go bindings for android.app.blob.
download
Package download provides Go bindings for android.app.
Package download provides Go bindings for android.app.
job
Package job provides Go bindings for android.app.job.
Package job provides Go bindings for android.app.job.
notification
Package notification provides Go bindings for android.service.notification.
Package notification provides Go bindings for android.service.notification.
role
Package role provides Go bindings for android.app.role.
Package role provides Go bindings for android.app.role.
usage
Package usage provides Go bindings for android.app.usage.
Package usage provides Go bindings for android.app.usage.
Package bluetooth provides Go bindings for android.bluetooth.
Package bluetooth provides Go bindings for android.bluetooth.
le
Package le provides Go bindings for android.bluetooth.le.
Package le provides Go bindings for android.bluetooth.le.
Desktop builds require CGO_CFLAGS and CGO_LDFLAGS pointing to a JDK:
Desktop builds require CGO_CFLAGS and CGO_LDFLAGS pointing to a JDK:
Package companion provides Go bindings for android.companion.
Package companion provides Go bindings for android.companion.
Package content provides Go bindings for android.content.
Package content provides Go bindings for android.content.
clipboard
Package clipboard provides Go bindings for android.content.
Package clipboard provides Go bindings for android.content.
permission
Package permission provides Go bindings for .
Package permission provides Go bindings for .
pm
Package pm provides Go bindings for android.content.pm.
Package pm provides Go bindings for android.content.pm.
preferences
Package preferences provides Go bindings for android.content.
Package preferences provides Go bindings for android.content.
resolver
Package resolver provides Go bindings for android.net.
Package resolver provides Go bindings for android.net.
Package credentials provides Go bindings for .
Package credentials provides Go bindings for .
graphics
pdf
Package pdf provides Go bindings for android.graphics.pdf.
Package pdf provides Go bindings for android.graphics.pdf.
hardware
biometric
Package biometric provides Go bindings for android.hardware.biometrics.
Package biometric provides Go bindings for android.hardware.biometrics.
camera
Package camera provides Go bindings for android.hardware.camera2.
Package camera provides Go bindings for android.hardware.camera2.
ir
Package ir provides Go bindings for android.hardware.
Package ir provides Go bindings for android.hardware.
lights
Package lights provides Go bindings for android.hardware.lights.
Package lights provides Go bindings for android.hardware.lights.
usb
Package usb provides Go bindings for android.hardware.usb.
Package usb provides Go bindings for android.hardware.usb.
health
connect
Package connect provides Go bindings for .
Package connect provides Go bindings for .
internal
jnierr
Package jnierr provides JNI exception-to-Go-error conversion.
Package jnierr provides JNI exception-to-Go-error conversion.
testjvm
Package testjvm creates and manages a JVM instance for use in tests.
Package testjvm creates and manages a JVM instance for use in tests.
Package location provides Go bindings for android.location.
Package location provides Go bindings for android.location.
altitude
Package altitude provides Go bindings for android.location.altitude.
Package altitude provides Go bindings for android.location.altitude.
media
audiomanager
Package audiomanager provides Go bindings for android.media.
Package audiomanager provides Go bindings for android.media.
audiorecord
Package audiorecord provides Go bindings for android.media.
Package audiorecord provides Go bindings for android.media.
player
Package player provides Go bindings for android.media.
Package player provides Go bindings for android.media.
projection
Package projection provides Go bindings for android.hardware.display.
Package projection provides Go bindings for android.hardware.display.
recorder
Package recorder provides Go bindings for android.media.
Package recorder provides Go bindings for android.media.
ringtone
Package ringtone provides Go bindings for android.media.
Package ringtone provides Go bindings for android.media.
session
Package session provides Go bindings for android.media.session.
Package session provides Go bindings for android.media.session.
net
Package net provides Go bindings for android.net.
Package net provides Go bindings for android.net.
nsd
Package nsd provides Go bindings for android.net.nsd.
Package nsd provides Go bindings for android.net.nsd.
vpn
Package vpn provides Go bindings for android.net.
Package vpn provides Go bindings for android.net.
wifi
Package wifi provides Go bindings for android.net.wifi.
Package wifi provides Go bindings for android.net.wifi.
wifi/p2p
Package p2p provides Go bindings for android.net.wifi.p2p.
Package p2p provides Go bindings for android.net.wifi.p2p.
wifi/rtt
Package rtt provides Go bindings for android.net.wifi.rtt.
Package rtt provides Go bindings for android.net.wifi.rtt.
nfc
Package nfc provides Go bindings for android.nfc.
Package nfc provides Go bindings for android.nfc.
os
battery
Package battery provides Go bindings for android.os.
Package battery provides Go bindings for android.os.
build
Package build provides Go bindings for android.os.
Package build provides Go bindings for android.os.
environment
Package environment provides Go bindings for android.os.
Package environment provides Go bindings for android.os.
keyguard
Package keyguard provides Go bindings for android.app.
Package keyguard provides Go bindings for android.app.
power
Package power provides Go bindings for android.os.
Package power provides Go bindings for android.os.
storage
Package storage provides Go bindings for android.os.storage.
Package storage provides Go bindings for android.os.storage.
vibrator
Package vibrator provides Go bindings for android.os.
Package vibrator provides Go bindings for android.os.
Package print provides Go bindings for android.print.
Package print provides Go bindings for android.print.
provider
calendar
Package calendar provides Go bindings for android.provider.
Package calendar provides Go bindings for android.provider.
contacts
Package contacts provides Go bindings for android.provider.
Package contacts provides Go bindings for android.provider.
documents
Package documents provides Go bindings for android.provider.
Package documents provides Go bindings for android.provider.
media
Package media provides Go bindings for android.provider.
Package media provides Go bindings for android.provider.
settings
Package settings provides Go bindings for .
Package settings provides Go bindings for .
se
omapi
Package omapi provides Go bindings for android.se.omapi.
Package omapi provides Go bindings for android.se.omapi.
security
keystore
Package keystore provides Go bindings for .
Package keystore provides Go bindings for .
Package speech provides Go bindings for android.speech.tts.
Package speech provides Go bindings for android.speech.tts.
Package telecom provides Go bindings for android.telecom.
Package telecom provides Go bindings for android.telecom.
Package telephony provides Go bindings for android.telephony.
Package telephony provides Go bindings for android.telephony.
tools
cmd/javagen command
cmd/jnigen command
cmd/specgen command
pkg/specgen
Package specgen generates Java API YAML specs from .class files using javap.
Package specgen generates Java API YAML specs from .class files using javap.
view
display
Package display provides Go bindings for android.view.
Package display provides Go bindings for android.view.
inputmethod
Package inputmethod provides Go bindings for android.view.inputmethod.
Package inputmethod provides Go bindings for android.view.inputmethod.
widget
toast
Package toast provides Go bindings for android.widget.
Package toast provides Go bindings for android.widget.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL