[工作积累] 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:
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:
NatvieAcitviy: JNI_OnLoad is not get called
For the startup library speicified by "android.app.lib_name", system will auto-load library on activity startup, but JNI_OnLoad is not get called, only libs loaded by System.loadLibrary() will.
but you can use native activity and load the library manually for the second time, so that JNI_OnLoad & all other activity binding function is exposed.
in AndroidManifest.xml:
<meta-data android:name="android.app.lib_name" android:value="GameLibrary" />
in Game Activity.java - load it manually:
1 public class GameActivity extends NativeActivity { 2 .... 3 static { 4 System.loadLibrary("GameLibrary"); 5 } 6 }