Browse Source

提交

master
richie 5 years ago
parent
commit
cf9f98acbf
  1. 12
      native/mylib/src/lib.rs

12
native/mylib/src/lib.rs

@ -9,7 +9,9 @@ use jni::objects::{JClass, JString};
// This is just a pointer. We'll be returning it from our function. We // This is just a pointer. We'll be returning it from our function. We
// can't return one of the objects with lifetime information because the // can't return one of the objects with lifetime information because the
// lifetime checker won't let us. // lifetime checker won't let us.
use jni::sys::jstring; use jni::sys::{jstring, jint};
use std::any::Any;
// This keeps rust from "mangling" the name and making it unique for this // This keeps rust from "mangling" the name and making it unique for this
// crate. // crate.
#[no_mangle] #[no_mangle]
@ -33,4 +35,10 @@ pub extern "system" fn Java_HelloWorld_hello(env: JNIEnv,
.expect("Couldn't create java string!"); .expect("Couldn't create java string!");
// Finally, extract the raw pointer to return. // Finally, extract the raw pointer to return.
output.into_inner() output.into_inner()
} }
#[no_mangle]
#[allow(non_snake_case)]
pub extern "system" fn Java_MyMath_add(env: JNIEnv, class: JClass, a: jint, b: jint) -> jint {
return a + b;
}

Loading…
Cancel
Save