Search code examples
androidandroid-ndk

Does JNI_OnLoad works with NativeActivity?


I am using NativeActivity and have setup and exported JNI_OnLoad in the shared library. But the JNI_OnLoad is not getting called !


Solution

  • No, JNI_OnLoad() wont work for the library called from NativeActivity (Credit). Instead, I guess ANativeActivity_onCreate() compensate for it.

    As seen in android source, NativeActivity does not call System.loadLibrary() but calls loadNativeCode() which does dlopen() directly.

    I had to use RegisterNatives() which could just as well be called in ANativeActivity_onCreate().

    Android Dev is fun /s