DioxusLabs / DioxusLabs/dioxus
`manganis::ffi` not working in minimal example
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
`manganis::ffi` is not working in a minimal example of its use (https://github.com/CAPage/minimal-ffi-repro) - receiving the error:
`JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.example.minimalffirepro.MinimalFFIReproAndroid" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]`
I investigated a number of problems, including checking whether or not the class is actually present in the APK (it is, I checked with Android studio.) I also attempted to manually load the class with both `find_class` and `load_class_with_classloader`, neither of which were able to load the class.
**Steps To Reproduce**
Set up a new Dioxus project, add a simple Kotlin class to `src/main/kotlin` and the corresponding `manganis::ffi` `extern "Kotlin"` block in your `main.rs`. Attempt to call a method of the Kotlin class from Rust. Or, take a look at my minimal reproduction (https://github.com/CAPage/minimal-ffi-repro).
**Expected behavior**
The object should be created and the method should be callable.
**Environment:**
- Dioxus version: 0.8.0-alpha.0 (also tried with 0.7.9)
- Rust version: 1.98.0-nightly
- OS info: MacOS 15.7.7
- App platform: Android. (Pixel 10/Android 16.0, emulated through Android Studio.)
**Questionnaire**
I have actually managed to get this working using a patched version of Dioxus (and I’m willing to work on this to fix it), but I don’t have a lot of context for manganis or the approach taken, outside of my own investigation - so would love to know if this is the right approach/a known issue/etc before moving forward!
Given that the issue seemed to be about which classloader was used (e.g. not a classloader that has access to the APK), including when `load_class_with_classloader` was called, my patch involved:
- Modifying `load_class_with_classloader` such that it takes an `activity` parameter, gets the classloader of the activity (`getClassLoader()`), and then uses `loadClass` to load the target class.
- Modifying the `manganis::ffi` macro such that it uses `load_class_with_classloader` rather than `find_class` .
When using this patched version of Dioxus, the minimal reproduction (https://github.com/CAPage/minimal-ffi-repro) works perfectly - both through `manganis::ffi` and when loaded manually through `load_class_with_classloader` .
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.