不是loadLib,是
static {
System.loadLibrary("你的库名");
}
这个是在类被加载的时候加载的,也就是你的Test。你说的有些没有使用load,是因为在系统启动的时候so已经被加载了。你可以通过命令行看到系统里面的很多so:
如果so被加载了,你就不需要再使用加载代码,可以直接用native接口
System.loadLibrary()是在使用Java的JNI机制时,会用到的一个非常重要的函数,它的作用即是把实现native方法的那个链接库load进来,或者load其他什么动态连接库。
System.loadLib()的实现(code在libcore/luni/src/main/java/java/lang/System.java这个文件中):
/**
* Loads and links the library with the specified name. The mapping of the
* specified library name to the full path for loading the library is
* implementation-dependent.
*
* @param libName
* the name of the library to load.
* @throws UnsatisfiedLinkError
* if the library could not be loaded.
*/
public static void loadLibrary(String libName) {
Runtime.getRuntime().loadLibrary(libName, VMStack.getCallingClassLoader());
}