Allowing Java-C++ interaction

Tyler Mandry tmandry at gmail.com
Fri Dec 23 02:51:59 UTC 2011


Hi all, and Merry Christmas.

We were discussing the importance of allowing Java and C++ to interact for
many people's apps in android-qt (thread: C++ and Java interaction in
Alpha3.) With the new separation of the JAR files, and use of a different
class loader for the app code, it has become very difficult to allow this.
Traditional native interface classes can no longer see the native methods
that are loaded by the separate class loader.

I did some playing around, and I think I found a simple solution that
works. If we separate out the code in qtmain_android.cpp into its own (very
small!) shared library, and allow the user's application code to be in one
library all by itself, we can load them in separate class loaders. While
you can't do Java-Java or Java-native interaction easily across the class
loader barrier, native-native interaction works fine since it's all the
same process. Simply load the Qt library in the /child/ class loader,
followed by the application code library in the /main/ class loader,
followed by the qtmain_android code in the /child/ class loader. Then the
user's Java code can see the user's C++ code and vice versa, because they
are all loaded under the same class loader.

I did a testcase of this (with libraries of my own, not Qt) and confirmed
that it works in a simple case. If no one sees any problems with this let's
implement it.

-- 
Tyler Mandry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/necessitas-devel/attachments/20111222/56d6ff55/attachment.html>


More information about the Necessitas-devel mailing list