Android 4.x.通过apk部署本机库并从其他应用程序加载

我有几个本机库,我想通过apk包部署它们(即将它们复制到libs文件夹或资源).

然后我需要安装单独的应用程序并使用以下方法加载这些库:

System.load(path_to_lib);

它可以通过哪种方式完成?据我所知,由于安全原因,我不能只使用/data/data/libs_package/lib/native_lib.so路径加载库.还有其他方法吗?

提前致谢.

最佳答案 请参阅android-ndk讨论组中的
this thread.

总而言之,谷歌的Android开发者说:

If the two applications have a shared user ID, then you can explicitely call System.loadLibrary() with the full path to the shared library you want to load.

But please do not try to do any of this. You are going to cause pain for your users — whether from updates of one or the other app causing incompatibilities and making you break, or the user uninstalling the other app and making you break, etc.

另一位开发人员提出以下解决方案:

So what I do now (and it works) is have a bunch of packages without a
shared user id (they are signed by the same key, but I don’t think
that is important here). The core app unzips the .so from the .apk of
the other packages (I already have a custom unpacker to workaround a
bunch of other Android bugs). I unpack them to a location known by
the core package and then dlopen() them from there.

点赞