在Android上加载具有依赖项的共享库

时间:2021-05-22 05:35:15

I'm porting a big chunk of native code with several interdependent libraries. Loading the code fails since Android linker only looks dependencies in /system/lib/ and not in the application install directory at /data/data/com.packagename.nnn/lib.

我正在使用几个相互依赖的库移植大量本机代码。加载代码失败,因为Android链接器只查看/ system / lib /中的依赖项,而不是/data/data/com.packagename.nnn/lib中的应用程序安装目录中的依赖项。

As a first workaround I loaded all .so's from Java with System.load() in correct dependency order. This solution isn't satisfactory for me mostly because the set of libraries changes from build to build due to plugin architecture. Also the UI shouldn't need to know that much about native libs.

作为第一个解决方法,我使用System.load()以正确的依赖顺序从Java加载所有.so。这个解决方案对我来说并不令人满意,因为由于插件架构,库集从一个版本变为另一个版本。 UI也不需要了解很多关于本机库的知识。

I've found that Android does not support RPATH or setting LD_LIBRARY_PATH for an app. The only workaround I found is building the libraries with fully qualified SONAMEs.

我发现Android不支持RPATH或为应用程序设置LD_LIBRARY_PATH。我发现的唯一解决方法是使用完全合格的SONAME构建库。

However some of the dependencies come pre-built.

然而,一些依赖项是预先构建的。

  1. Is it possible compile fully qualified NEEDED tag into my own library even when the needed .so does not have fully qualified SONAME?

    即使所需的.so没有完全合格的SONAME,是否可以将完全合格的NEEDED标签编译到我自己的库中?

  2. Or is it possible to modify existing .so and replace its SONAME or NEEDED with fully qualified one without recompiling?

    或者是否可以修改现有的.so并用完全合格的替换它的SONAME或NEEDED而无需重新编译?

1 个解决方案

#1


0  

Mozilla Fennec loads a bunch of shared objects from a custom cache directory under their /data/data/package/ directory, you might take a look at their source.

Mozilla Fennec从/ data / data / package /目录下的自定义缓存目录加载一堆共享对象,您可以查看它们的源代码。

#1


0  

Mozilla Fennec loads a bunch of shared objects from a custom cache directory under their /data/data/package/ directory, you might take a look at their source.

Mozilla Fennec从/ data / data / package /目录下的自定义缓存目录加载一堆共享对象,您可以查看它们的源代码。