首页 > 代码库 > [工作积累] Android dynamic library & JNI_OnLoad

[工作积累] Android dynamic library & JNI_OnLoad

Bionic libc doesn‘t load dependencies for current .so file (diff from Windows or Linux)

so a explicit calling of Java‘s System.loadLibrary() is needed, in order to load depedency libraries. otherwise the original .so will fail to load.

 

JNI_OnLoad will be called mostly on  System.LoadLibrary() or equavilent calls

System.loadLibrary("gnustl_shared");

 

the .so file is loaded & and symbol get loaded by common dynamic library function:

dlopen

dlsym

 

if the symbol "JNI_OnLoad" is not found in the lib, dalvik will simply do nothing, but a Debug Log: No JNI_OnLoad found in xxx.so, skipping init.

 

details at:

 dalvik/vm/Native.c

 

NatvieAcitviy: JNI_OnLoad is not get called

For the startup library speicified by "android.app.lib_name", JNI_OnLoad is not get called,

only libs loaded by System.loadLibrary() will.

[工作积累] Android dynamic library & JNI_OnLoad