-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): setup JNI support for non-rust Android apps
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
Berend Sliedrecht
committed
Jun 4, 2024
1 parent
8f3ab48
commit 55a293d
Showing
7 changed files
with
155 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
use android_activity::AndroidApp; | ||
use mobile_tests::run_tests; | ||
|
||
use jni::{JavaVM, JNIEnv, objects::JClass, sys::jobject}; | ||
|
||
extern "system" { | ||
fn Java_id_animo_SecureEnvironment_set_1env<'local>(env: JNIEnv<'local>, _class: JClass<'local>); | ||
} | ||
|
||
#[no_mangle] | ||
fn android_main(_app: AndroidApp) { | ||
fn android_main(app: AndroidApp) { | ||
// Since we cannot use the jvm pointer set by `android_activity` we manually call the exposed | ||
// method with a null pointer for a class (as it is not used anyways) and the jni env we | ||
// receive from the `app`. | ||
let jvm = unsafe { JavaVM::from_raw(app.vm_as_ptr() as *mut _) }.unwrap(); | ||
let env = unsafe { JNIEnv::from_raw(jvm.attach_current_thread().unwrap().get_raw()) }.unwrap(); | ||
let clazz = unsafe { JClass::from_raw(std::ptr::null::<jobject>() as *mut _) }; | ||
unsafe { Java_id_animo_SecureEnvironment_set_1env(env, clazz) }; | ||
|
||
run_tests(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters