-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading custom Java classes #82
Comments
Hi, sorry I missed this question when you asked it. Yeah this is an awkward Android + JNI issue for native apps. One option is to look up the class loader for the Activity instance that you have access to and use that instead of find_class. E.g. this is what I do in Bluey: https://github.com/rib/bluey/blob/5f351c50e6f396bc4fef9c050599f9668c63b339/bluey/src/android/session.rs#L1017 Potentially android-activity could provide some kind of utility for this but ideally I don't really want to expose Hope that helps though. |
Thanks @rib For now I ask the user to call a Java method in their GameActivity subclass and I'd like to avoid this if possible. I'll try your approach as it seems to be exactly what I need. |
a related question. How can i include the aar lib files in my project? |
Hi,
I am using the GameActivity and I need to instanciate a Java class that I wrote. This class is not referenced anywhere on the Java side but it is present in the APK. When I call
env.find_class
inside myandroid_main
function, I get a ClassNotFoundException. I have read that this could happen inside a thread not spawned by the JVM that would use the default ClassLoader. I have also found this comment just before the call toandroid_main
:I think this explain my issue. Is there a typical way around this? I've heard about the
JNI_OnLoad
function, but I'm afraid it would interfear.How difficult whould it be to lift this limitation, if it is something doable?
Thanks for this amazing crate!
The text was updated successfully, but these errors were encountered: