Crate robius_android_env
source ·Expand description
Abstractions for Rust access to Android state (native Java objects) managed by UI toolkits.
§Usage of this crate
This crate exists for two kinds of downstream users:
- The UI toolkit that exposes its key internal states that hold
the current Android activity being displayed and the Java VM / JNI environment.
Either the UI toolkit or the app itself should set these states on startup,
specifically using
set_vmandset_activity_getterfunctions. - The Rust platform feature crates that need to access the current activity and JNI environment in order to interact with the Android platform.
§Supported UI toolkits
- Makepad: enable the
makepadCargo feature. - Others coming soon! (in the meantime, see below)
§Usage of this crate for other UI toolkits
For any other UI toolkits not listed above, you don’t need to enable any cargo features. Instead, your application code must manually provide two key states:
- a reference to the current Android activity.
- a reference to the current Java VM instance (and JNI environment).
This can be achieved by doing the following:
- Enable the
setCargo feature, and - Provide an ActivityGetterFn callback by calling
set_activity_getter(). - If the ActivityGetterFn cannot provide a low-level
JNIEnvobject, the application must also call theset_vm()function.
Modules§
- Re-exports of low-level pointer types from the
jni-syscrate.
Structs§
- FFI-compatible JNIEnv struct. You can safely use this as the JNIEnv argument to exported methods that will be called by java. This is where most of the magic happens. All methods on this object are wrappers around JNI functions, so the documentation on their behavior is still pretty applicable.
- Wrapper around [
sys::jobject] that adds a lifetime to ensure that the underlying JNI pointer won’t be accessible to safe Rust code if the object reference is released. - The Java VM, providing Invocation API support.
Functions§
- Registers the function that retrieves pointers to the current JNI environment (optional) and the current Android Activity (as a jobect).
- Sets the current Java VM.
- Invokes the given closure
fwith the current JNI environment and the current activity.
Type Aliases§
- The function signature registered by the UI toolkit that provides pointers to current JNI environment (optional) and the current activity (as a jobect).