MaulingMonkey/jni-bindgen

jni error

dvc94ch opened this issue · 2 comments

I'm not sure what the problem is or how to proceed with debugging. Do you have any ideas?

#![cfg(target_os = "android")]

use jni_android_sys::android::content::Context;

ndk_glue::ndk_glue!(main);

fn main() {
    let vm = unsafe { jni_glue::VM::from_jni_local(&*ndk_glue::native_activity().vm()) };

    let native_lib_dir = vm.with_env(|env| {
        let context = Context::new(env).unwrap();
        //let info = context.getApplicationInfo().unwrap().unwrap();
        //let lib_dir = info.nativeLibraryDir().unwrap();
        //lib_dir.to_string().unwrap()
        ""
    });

    println!("native lib dir is {:?}", native_lib_dir);
}
02-19 12:50:53.938 13658 13658 F DEBUG   : pid: 13609, tid: 13654, name: Thread-2  >>> rust.example.jni <<<
02-19 12:50:53.945 13658 13658 F DEBUG   :     #08 pc 000000000001d7e0  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (jni_glue::env::Env::new_object_a::h6744845ef91a6224+76)
02-19 12:50:53.945 13658 13658 F DEBUG   :     #09 pc 000000000001ddbc  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (jni_android_sys::android::content::Context::new::hcf0b513db4bff890+152)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #10 pc 0000000000005308  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (jni::main::_$u7b$$u7b$closure$u7d$$u7d$::hd7969440a25f58b6+20)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #11 pc 0000000000004b78  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (jni_glue::vm::VM::with_env::ha2bfdd8554ee29ca+416)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #12 pc 0000000000004d7c  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (jni::main::hfe40f5c643af1c31+44)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #13 pc 0000000000010878  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (ndk_glue::init::_$u7b$$u7b$closure$u7d$$u7d$::h1f9650c5afa39c72+152)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #14 pc 000000000000c2b4  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::sys_common::backtrace::__rust_begin_short_backtrace::hf5d359fb8c6f708f+16)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #15 pc 000000000000b894  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hea75f786b66b8340+16)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #16 pc 000000000001305c  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (_$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hd818eb5bdbde1faa+16)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #17 pc 0000000000014598  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::panicking::try::do_call::hbc0d5782dfb4d564+44)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #18 pc 0000000000032990  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (__rust_maybe_catch_panic+32)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #19 pc 0000000000014440  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::panicking::try::hbfe660383477c598+80)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #20 pc 00000000000130e4  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::panic::catch_unwind::hca591d4539c5427a+16)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #21 pc 000000000000b6c8  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hcc10361d60d81092+212)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #22 pc 0000000000008f20  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h45da1a1034e1bb1b+16)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #23 pc 000000000002b18c  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h72164f22cf22b003+72)
02-19 12:50:53.946 13658 13658 F DEBUG   :     #24 pc 00000000000324ac  /data/app/rust.example.jni-4w_2VFpG0ATyZAaj3WU-YA==/lib/arm64/libjni.so (std::sys::unix::thread::Thread::new::thread_start::h8fae6fef275a32d6+20)

related to rust-mobile/ndk#13

@MaulingMonkey any ideas?

I sincerely have never seen anyone create a 'new' android context this way. But the trace looks like the error is coming from where the new Context object is created. If we had the JNI stack trace, you'll be able to figure out exactly what the problem is. Are you sure this does not have anything to do with the ClassLoader?