从android的obb文件夹加载.so本机库

时间:2021-08-03 06:01:26

I have an .so file that I packed into an obb expansion. It's about 20 megabytes.

我有一个.so文件,我打包成一个obb扩展。它大约是20兆字节。

I'm trying to use

我正在尝试使用

System.load("/storage/emulated/0/Android/obb/com.mypackage.myapp/libtest.so");

to load the library. But I get the error:

加载库。但我得到错误:

dlopen("/storage/emulated/0/Android/obb/com.mypackage.myapp/libtest.so", RTLD_LAZY) failed: dlopen failed: couldn't map "/storage/emulated/0/Android/obb/com.mypackage.myapp/libtest.so" segment 2: Permission denied

dlopen(“/ storage / emulated / 0 / Android / obb / com.mypackage.myapp / libtest.so”,RTLD_LAZY)失败:dlopen失败:无法映射“/ storage / emulated / 0 / Android / obb / com。 mypackage.myapp / libtest.so“第2段:权限被拒绝

type=1400 audit(0.0:8): avc: denied { execute } for path="/storage/emulated/0/Android/obb/com.mypackage.myapp/libtest.so" dev="fuse" ino=367663176224 scontext=u:r:untrusted_app:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0

s =文本类型= 1400审计(0.0:8):avc:拒绝{execute} for path =“/ storage / emulated / 0 / Android / obb / com.mypackage.myapp / libtest.so”dev =“fuse”ino = 367663176224 scontext = u:r:untrusted_app:s0 tcontext = u:object_r:fuse:s0 tclass = file permissive = 0

So I realized that we're not permitted to have an executable there.

所以我意识到我们不允许在那里有可执行文件。

So my question is,

所以我的问题是,

1- Where should extract the file to be able to do this?

1-在哪里提取文件才能做到这一点?

2- What function call should I make?

2-我应该拨打什么函数?

Thank you.

1 个解决方案

#1


0  

Copy the file to any location of your choice under your app's private internal storage folder, make sure it is marked read only and executable (not writable, especially by anyone else!). This is the only tree of locations typically writable by an application where executables are permitted.

将文件复制到您选择的应用程序专用内部存储文件夹下的任何位置,确保将其标记为只读且可执行(不可写,尤其是其他任何人!)。这是唯一一个通常可由应用程序写入的位置树,其中允许可执行文件。

You can determine the private folder location by calling getFilesDir() on an initialized Activity or Service Context.

您可以通过在初始化的活动或服务上下文上调用getFilesDir()来确定私有文件夹位置。

There are a number of existing questions here which demonstrate mechanisms for file copying in Java.

这里有许多现有问题,它们演示了Java中文件复制的机制。

#1


0  

Copy the file to any location of your choice under your app's private internal storage folder, make sure it is marked read only and executable (not writable, especially by anyone else!). This is the only tree of locations typically writable by an application where executables are permitted.

将文件复制到您选择的应用程序专用内部存储文件夹下的任何位置,确保将其标记为只读且可执行(不可写,尤其是其他任何人!)。这是唯一一个通常可由应用程序写入的位置树,其中允许可执行文件。

You can determine the private folder location by calling getFilesDir() on an initialized Activity or Service Context.

您可以通过在初始化的活动或服务上下文上调用getFilesDir()来确定私有文件夹位置。

There are a number of existing questions here which demonstrate mechanisms for file copying in Java.

这里有许多现有问题,它们演示了Java中文件复制的机制。