manganis: load FFI classes from the activity classloader, not FindClass
JNIEnv::find_class resolves against the system classloader on a thread attached from native code, which cannot see APK classes (#5629). Route the generated #[manganis::ffi] type lookup through load_class_from_classloader, and reimplement that helper to ask the activity's own ClassLoader.loadClass instead of Class.forName. Ask the activity INSTANCE, not its Class: Context.getClassLoader() is documented to return a loader for the application package unconditionally, whereas Class.getClassLoader() returns null for classes loaded by the bootstrap loader. Describe and clear the pending Java exception on every error path. jni 0.21 leaves the exception pending when a call returns Err, and the next JNI call then aborts the process with 'JNI DETECTED ERROR IN APPLICATION: ... called with pending exception' -- which is what turns a recoverable ClassNotFoundException into an unreadable ART abort.
This commit is contained in:
1 parent
07dddd569e
commit
48baafc3ff
2 files changed
+46
-7
No files matched your search
@@ -398,7 +398,7 @@ impl FfiBridgeParser {
|
||||
// Use with_activity which returns Option<R>, wrapping our Result in the Option
|
||||
let inner_result: Option<Result<Self, String>> = manganis::android::with_activity(|mut env, activity| {
|
||||
// Find the class
|
||||
let class_result = env.find_class(#class_name_lit);
|
||||
let class_result = manganis::android::load_class_from_classloader(env, activity, #class_name_lit);
|
||||
let class = match class_result {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Some(Err(format!("Failed to find class {}: {:?}", #class_name_lit, e))),
|
||||
|
||||
Reference in new issue
Block a user