Closed GoogleCodeExporter closed 8 years ago
If I understand this correctly, basically, initializing a class inside a random
thread created outside the virtual machine crashes Android? I think that would
be a bug of Android... If so, simply including Class.forName("CallbackEvent")
alongside Loader.load() in your Java code should work around the issue until
the Android team fixes it... Let me know what you think, thanks.
Original comment by samuel.a...@gmail.com
on 19 Oct 2011 at 3:45
I'm not 100% sure what is happening but it does look like that
JavaCPP_getClass() is failing from the outside thread even though the call it
done after AttachCurrentThread(). But using the work around and getting all the
jclass from OnLoad makes everything work.
I attached the test code in case you want to try it out. It is the Android
project but everything but the JNITestActivity.java is platform independent.
Original comment by bid...@gmail.com
on 19 Oct 2011 at 3:05
Attachments:
I would like to know, does calling Class.forName("CallbackEvent") alongside
Loader.load() make everything work too?
Original comment by samuel.a...@gmail.com
on 20 Oct 2011 at 7:27
No, sadly that didn't work. Even when I changed it to
Class.forName("_CallbackEvent");
which is the Java class that extends Pointer. The call itself failed with class
not found.
However, if we add
Callback blah = Callback.ZERO;
then it works. If you look at the code, you will see ZERO is loaded from the C
class, which forces the look up.
Original comment by bid...@gmail.com
on 20 Oct 2011 at 12:14
Right, you do need to specify the package namespace, something like
Class.forName("com.unicoi.jnitest.demo.FuncTest$_CallbackEvent")
Original comment by samuel.a...@gmail.com
on 20 Oct 2011 at 12:18
Class.forName("com.unicoi.jnitest.demo.FuncTest$_CallbackEvent");
didn't help either. Still crashes.
Adding something like
CallbackEvent.ZERO.toString();
still makes it all happy.
I think I might use that as a work around for now.
Original comment by bid...@gmail.com
on 20 Oct 2011 at 2:31
Well, you should try
Class.forName("com.unicoi.jnitest.demo.FuncTest$CallbackEvent");
If this is the class that requires initialization...
Original comment by samuel.a...@gmail.com
on 21 Oct 2011 at 6:35
I see, it seems like Android uses a couple of different classloaders that
change depending on which thread we call it from, some details:
http://groups.google.com/group/android-developers/browse_thread/thread/e090b94fe
958ab31#msg_d848ae7f85bd3167
So, you were right, we should load these classes from JNI_OnLoad() if possible,
since this does not appear like something the Android team is going to fix
anytime soon. I implemented the workaround in the SVN repository. Let me know
that it works for you, thanks!
Original comment by samuel.a...@gmail.com
on 22 Oct 2011 at 6:00
This problem has been fixed too. Thank you!
Original comment by bid...@gmail.com
on 25 Oct 2011 at 2:10
You are welcome!
Original comment by samuel.a...@gmail.com
on 29 Oct 2011 at 5:12
Original issue reported on code.google.com by
bid...@gmail.com
on 17 Oct 2011 at 4:49