如何从另一个本机库(.so)加载本机库(.so)? [英] How do I load a native library (.so) from another native library (.so)?

查看:136
本文介绍了如何从另一个本机库(.so)加载本机库(.so)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我现在的代码就像从Java层加载库(例如liba.so),在内部liba.so加载libb.so.因此,如果我必须将所有库打包到APK中,然后将其安装在没有root用户访问权限的设备上,那么构建项目的过程是什么,在该过程中,来自Java层的一个加载调用将加载两个库,即第一个liba.那么(直接调用),然后是libb.so(第二个调用,嵌套调用,从liba.so调用)?

So, my code right now is like it loads library (say liba.so) from Java-layer and internally liba.so loads 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)?

推荐答案

如果liba.so和libb.so都打包到您的APK中,则安装程序会将两者都打包到

If both liba.so and libb.so are packed into your APK, then the installer will unpack both to the nativeLibraryDir.

从Java,loadLibrary()将自动在此目录中查找.但是dlopen()无法识别此路径.您必须提供dlopen()到已安装libb.so的完整路径.

From Java, loadLibrary() will look in this directory automatically. But dlopen() is not aware of this path. You must provide to dlopen() the full path to the installed libb.so.

或者,您可以从Java加载libb,然后它将在内存中,并且liba将找到它的导出符号,而无需dlopen().

Alternatively, you can load libb from Java, then it will be in memory and liba will find it's exported symbols without dlopen().

如果您需要更好地了解将库打包为APK的过程,请查阅这个绝妙的答案.

If you need to understand better the process of packing the libraries into APK, consult this wonderful answer.

这篇关于如何从另一个本机库(.so)加载本机库(.so)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆