Search code examples
androidc++android-ndkjava-native-interfaceclassloader

Android NDK : How to get a Class Loader With a NativeActivity and native_app_glue?


Ok, I have a native application, that is ran off the main thread, which requires C++ to access some java code. I kept getting error's with FindClass() as my class loader defaults to my system, which doesn't load any of my app's java sources.

A common way around this is to globally reference the classes from my application at JNI_OnLoad, before my code is forked into another thread, so the ClassLoader can be from my application , of which can find all my classes, however since I'm implementing a NativeActivity with native_app_glue, JNI_OnLoad never gets called.

There is a reference to a method "getClassLoader" , here : https://groups.google.com/forum/#!msg/android-ndk/cKZRjSMUemw/MPXgmjYZ9qkJ

Which is suppose to work, however I can't find it, and have no idea of it implementation.

I'm just looking for an example or too, thanks.


Solution

  • Ok, I have done it.

    The answer is here: android Flurry integration with NDK app, just , instead of doing this/is/my/java/class , do this.is.my.java.class instead - then it works ;D