android v8 库,Android系统从armeabi,armeabi-v7a,arm64-v8a加载本机库(so文件)是什么规则?(What's rule does Android syste...

Android系统从armeabi,armeabi-v7a,arm64-v8a加载本机库(so文件)是什么规则?(What's rule does Android system load native library(so file) from armeabi,armeabi-v7a,arm64-v8a?)

假设我们在下面有一个jni文件夹结构。

armeabi

a.so

b.so

armeabi-v7a

a.so

在基于ARMv7的设备上,我想加载b.so,但是在“armeabi-v7a”文件夹下没有b.so,因此系统会报告未找到的库错误,或者使用b.so文件夹下的“ armeabi“?

甚至更多,系统在armeabi , armeabi-v7a , arm64-v8a , x86 , x86_64寻找这样一个文件的顺序是什么? 例如,在基于x86_64的设备上,系统首先在文件夹x86_64查找so文件,但如果找不到,系统会继续按arm64-v8a在x86 , arm64-v8a , armeabi-v7a , armeabi中查找文件吗?

Assume we have a jni folder structure below.

armeabi

a.so

b.so

armeabi-v7a

a.so

On a ARMv7-based device, I want to load b.so, but the there is no b.so under folder "armeabi-v7a", so will the system report a not found library error or use the b.so under folder "armeabi"?

And even more, what order does system look for a so file among armeabi,armeabi-v7a,arm64-v8a,x86,x86_64? For example, on a x86_64-based device, system look for the so file in folder x86_64 first, but if not found, will system continue to look for the file in x86,arm64-v8a,armeabi-v7a,armeabi in sequence?

原文:https://stackoverflow.com/questions/35860727

更新时间:2019-12-09 06:05

最满意答案

我相信它会回答你的问题:

Play商店和包管理器都希望在APK中的文件路径中查找匹配以下模式的NDK生成的库:

/lib//lib.so

如果系统找不到它所期望的本地共享库,则它不能使用它们。 在这种情况下,应用程序本身必须将库复制过来,然后执行dlopen()。

进一步在页面下方是这个特定位:

安装时自动提取本机代码

在安装应用程序时,软件包管理器服务扫描APK,并查找表单的任何共享库:

lib//lib.so

如果找不到,并且您已经定义了辅助ABI,则该服务会扫描该表单的共享库:

lib//lib.so

当它找到它正在查找的库时,软件包管理器将它们复制到应用程序的数据目录(data / data // lib /)下的/lib/lib.so。 如果根本没有共享对象文件,则应用程序会生成并安装,但会在运行时崩溃。

所以在你的情况下,如果你在armeabi-v7a架构上,你必须复制lib/armeabi/libb.so文件并使用dlopen(),因为PackageManager不知道需要在你的应用中加载什么内容,但是在lib/armeabi-v7a目录中找到了一些东西。

I believe it answers your questions:

Both the Play Store and Package Manager expect to find NDK-generated libraries on filepaths inside the APK matching the following pattern:

/lib//lib.so

If the system does not find the native shared libraries where it expects them, it cannot use them. In such a case, the app itself has to copy the libraries over, and then perform dlopen().

Further down the page is this particular bit:

Automatic extraction of native code at install time

When installing an application, the package manager service scans the APK, and looks for any shared libraries of the form:

lib//lib.so

If none is found, and you have defined a secondary ABI, the service scans for shared libraries of the form:

lib//lib.so

When it finds the libraries that it's looking for, the package manager copies them to /lib/lib.so, under the application's data directory (data/data//lib/). If there is no shared-object file at all, the application builds and installs, but crashes at runtime.

So in your case if you are on a armeabi-v7a architecture, you'll have to copy the lib/armeabi/libb.so file over and use dlopen() as the PackageManager knows nothing of what needs to be loaded in your app but did find something in the lib/armeabi-v7a directory.

2016-03-08

相关问答

如果您需要同时支持armeabi和armeabi-v7a那么只需从库项目中删除armeabi-v7a库。 但是,如果可以放弃armeabi支持,那么从库项目中删除armeabi库,并在主项目中将armeabi库移动到新的armeabi-v7a文件夹中。 注意:如果你这样做,记下这个未经证实的错误报告。 你可以在我的答案这里阅读更多关于这个。 If you need to support both armeabi and armeabi-v7a then just delete the armeab

...

我最终使用Android NDK中的arm-linux-androideabi-objdump程序拆解了.so文件。 在反汇编代码中,我找到了vmaxnm.f32指令,该指令存在于armeabi-v7a指令集中,但不存在于armeabi中。 基于此,我得出结论,.so编译为armeabi-v7a。 可能还有其他指令可供我查找,但我对ARM指令集并不熟悉。 我很幸运,这个是相当明显的(因为它是一个浮点运算,是armeabi和armeabi-v7a之间的主要区别之一)。 感谢发布者的想法。 I end

...

最后我通过放置来理清 abi { enable false reset() include 'x86', 'armeabi-v7a' universalApk true } multiDexEnabled true但我不知道这是排除了问题还是忽略了错误 ndk.abiFilters configuration means that only selected processor architectures of native libraries will be included in the fi

...

取决于您的本机代码,但v7a支持硬件浮点运算,这是一个巨大的差异。 armeabi可以在所有设备上正常工作,但速度会慢一些,不会更新新设备的CPU功能。 为您的特定应用程序采取一些基准测试,但删除armeabi-v7a二进制文件通常不是一个好主意。 如果您需要减小大小,您可能需要为旧的(armeabi)和较新的(armeabi-v7a)设备分别安装两个apks。 Depends on what your native code does, but v7a has support for hardw

...

你见过: http : //developer.android.com/ndk/guides/abis.html#am 我相信它会回答你的问题: Play商店和包管理器都希望在APK中的文件路径中查找匹配以下模式的NDK生成的库: /lib//lib.so

如果系统找不到它所期望的本地共享库,则它不能使用它们。 在这种情况下,应用程序本身必须将库复制过来,然后执行dlopen()。 进一步在页面下方是这个特定位: 安装时自动提取本机代码 在安装应用程序时,软件包管理器服务扫

...

终于用@ user1056837的帮助解决了我的问题。 我需要搜索的奇怪的事情是: 对于ABI“x86”(至少?),当你想使用依赖于其他库的libmylib.so时,你只需要加载libmylib.so: System.loadLibrary("mylib");

但是对于ABI“armeabi-v7a”(至少?),你必须手动加载你的lib,你的lib的依赖关系,以及你的lib依赖的依赖... System.loadLibrary("dep1");

System.loadLibrary("dep2"

...

当我将renderscriptTargetApi更改为21时,问题就解决了。之前它是19,因为它加载了32位二进制文件。 The issue got solved when I changed the renderscriptTargetApi to 21. Previously it was 19, due to which it was loading 32 bit binaries.

Android使用-mthumb因为它生成更紧凑的代码。 处理器的低下与它无关。 在普通的ARM指令集中,每条指令都是32位的,而且每条指令都很有表现力(有不同的指令可以做很多不同的事情)。 不幸的是,这也意味着代码可能有点大,因为每条指令都需要4个字节。 我们引入了拇指指令集来解决这个问题 - 这里每条指令只有16位长,因此您可以在同一个空间中容纳两倍的指令,但由于指令较短,因此没有多少不同的指令。 每条指令仍然在32位寄存器上运行,否则其行为与ARM指令完全相同,所以它只是一种不同的,更紧凑的

...

我通过添加'armeabi-v7a'文件夹并将'.so'文件放入其中来解决。 I have solved by add a 'armeabi-v7a' folder and put the '.so' file into it.

没有必要告诉工具提供下一个最好的工具,应该自动完成。 如果设备报告也支持armeabi-v7a,它应该会收到包含它的APK。 编辑: 鉴于您的屏幕截图,您的应用程序似乎为arm64-v8a架构提供了本机库,因此将提供arm64-v8a库,而不是armeabi-v7a 。 另请注意,一个设备无法为同一个应用程序加载来自不同体系结构的库,即您不能指望某些库以64位加载,而其他一些库则以32位加载。 即使使用包含所有ABI的“胖”APK,Android平台也只会在安装您的应用时选择一个ABI并丢弃所有其

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值