Crate jni_min_helper

Source
Expand description

Minimal helper for jni-rs, supporting dynamic proxies, Android dex embedding and broadcast receiver. Used for calling Java code from Rust.

jni is re-exported here for the user to import jni functions, avoiding version inconsistency between jni and this crate.

This crate uses ndk_context::AndroidContext on Android, usually initialized by android_activity. Examples for Android are provided in the crate page.

Please make sure you are viewing documentation generated for your target.

Re-exports§

pub use jni;

Structs§

BroadcastReceiver
Handles android.content.BroadcastReceiver object backed by JniProxy.
BroadcastWaiter
Waits for intents received by the managed BroadcastReceiver.
JniClassLoader
Runtime class data loader. Wraps a global reference of java.lang.ClassLoader.
JniProxy
Java dynamic proxy with an invocation handler backed by the Rust closure.

Traits§

AutoLocalGlobalize
Converts an AutoLocal<'_> to an GlobalRef.
JObjectAutoLocal
Used for calling jni_clear_ex() and turning an owned JObject<'_> reference (which leaks memory on dropping in a Rust main thread permanently attached to the JVM) into an AutoLocal which deletes the reference from the environment on dropping. Works with android_activity. Note that borrowed references (&JObject<'_>) doesn’t cause memory leak.
JObjectGet
Gets the value from the Java object; calls jni_clear_ex() for an error.
JObjectNew
Creates the Java object (wrapper) for the Rust value.
JValueGenGet
Gets the value returned from the Java method; calls jni_clear_ex() for an error.

Functions§

android_api_level
Gets the API level (SDK version) of the current Android OS.
android_app_name
Gets the raw name of the current Android application, parsed from the package name.
android_app_package_name
Gets the package name of the current Android application.
android_context
Gets the current android.content.Context, usually a reference of NativeActivity. This depends on crate ndk_context.
block_for_timeout
Convenient blocker for asynchronous functions, based on futures_lite and futures_timer. Warning: Blocking in the android_main() thread will block the future’s completion if it depends on event processing in this thread (check your glue crate like android_activity).
jni_attach_permanently
Calls jni_get_vm() and tries attaching the current thread to the JVM permanently, in order to make jni_with_env faster. Does nothing and returns false if the thread is currently attached (this behaviour is determined by jni-rs).
jni_clear_ex
It calls JNIEnv::exception_clear() which is needed for handling Java exceptions, Not clearing it may cause the native program to crash on the next JNI call. Heavily used inside this crate, with Result::map_err().
jni_clear_ex_ignore
It is the same as jni_clear_ex_silent() without storing the exception for jni_last_cleared_ex().
jni_clear_ex_silent
It is the same as jni_clear_ex() without printing error information. Use it with Result::map_err() prior to functions from this crate to avoid error printing.
jni_get_vm
Gets the JavaVM from current Android context.
jni_last_cleared_ex
Takes away the stored reference of java.lang.Throwable of the last Java exception cleared inside this crate (current thread).
jni_with_env
Workaround for https://github.com/jni-rs/jni-rs/issues/558. Calls jni_get_vm(), attaches the current thread to the JVM and executes the closure. The thread may be dettached if it has not been attached previously.