Crates.io | ironbird_jni_context |
lib.rs | ironbird_jni_context |
version | 0.1.0 |
source | src |
created_at | 2022-11-05 22:05:20.507446 |
updated_at | 2022-11-05 22:05:20.507446 |
description | Access to JavaVM for Flutter JNI libraries. |
homepage | |
repository | |
max_upload_size | |
id | 706157 |
size | 11,474 |
This crate can be used to get access to JavaVM from Rust code.
It defines JNI_OnLoad
function which is called by JVM when the library is loaded. It saves the pointer to JavaVM, which can be accessed later.
It also attempts to store the class loader that loaded Flutter application.
This only works if the dylib that uses this crate is loaded from Java using System.loadLibrary
. It will not work if the dylib is loaded from other
code (i.e. through dlopen
).
This crate also assumes that System.loadLibrary
is called from main
thread. It will remember main thread looper and provides functionality
to schedule callbacks to be run on main thread.
let context = JniContext::get().unwrap();
let java_vm = context.java_vm();
let env = java_vm.attach_to_current_thread();
// ...
context.schedule_on_main_thread(|| {
// This will be run on main thread
println!("Hello from main thread!");
});