简体   繁体   English

如何从另一个本机库(.so)加载本机库(.so)?

[英]How do I load a native library (.so) from another native library (.so)?

So, my code right now is like it loads library (say liba.so) from Java-layer and internally liba.so loads libb.so. 因此,我现在的代码就像是从Java层加载库(例如liba.so),在内部从liba.so加载libb.so。 So, if I have to pack all the libraries inside an APK and install it on a device with no root access then what is the procedure to structure my project in which one load call from Java-layer will load both the libraries, first liba.so (direct call) and then libb.so (second call, nested call, call from liba.so)? 因此,如果我必须将所有库打包到一个APK中,并且将其安装在没有root用户访问权限的设备上,那么构建项目的过程是什么,在该过程中,来自Java层的一个加载调用将加载两个库,第一个liba。所以(直接调用),然后是libb.so(第二个调用,嵌套调用,从liba.so调用)?

If both liba.so and libb.so are packed into your APK, then the installer will unpack both to the nativeLibraryDir . 如果liba.so和libb.so都打包到您的APK中,则安装程序会将两者都解压缩到nativeLibraryDir

From Java, loadLibrary() will look in this directory automatically. 从Java,loadLibrary()将自动在此目录中查找。 But dlopen() is not aware of this path. 但是dlopen()不知道该路径。 You must provide to dlopen() the full path to the installed libb.so. 您必须向dlopen()提供已安装libb.so的完整路径。

Alternatively, you can load libb from Java, then it will be in memory and liba will find it's exported symbols without dlopen(). 另外,您可以从Java加载libb,然后它将在内存中,并且liba将找到它的导出符号,而无需dlopen()。

If you need to understand better the process of packing the libraries into APK, consult this wonderful answer . 如果您需要更好地了解将库打包为APK的过程,请查阅此精彩答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM