【问题标题】:Will Android automatically load the "best" .so file for the device?Android 会自动加载设备的“最佳”.so 文件吗?
【发布时间】:2011-11-14 07:35:10
【问题描述】:
我正在编写一个需要一些 JNI 代码的应用程序。
这段代码涉及浮点处理,所以我希望它尽可能快。因此我想支持 ARM5 和 ARM7 架构。在我的 Application.mk 中它说:
APP_ABI := all
... 构建过程为 ARM5、ARM7 和 x86 编译模块。我验证了所有 .so 文件最终都在 .apk 文件中。
现在的问题是:Android 会根据运行平台自动加载“最佳”.so 文件吗?换句话说:它会在 ARM5 设备上加载 ARM5 模块,在 ARM7 设备上加载 ARM7 模块吗?
【问题讨论】:
标签:
android
architecture
dynamic
load
【解决方案1】:
是的。
在 ARMv5 或 ARMv6 设备 (CPU) 上,将使用 ARMv5 二进制文件 (APP_ABI = armeabi)
在 ARMv7 设备上,系统将看到 ARMv7 二进制文件可用并将使用它 (APP_ABI = armeabi-v7a)
在 NDK 文档中,我们可以阅读:
III.2. Android Platform ABI support:
------------------------------------
The Android system knows at runtime which ABI(s) it supports. More
precisely, up to two build-specific system properties are used to
indicate:
- the 'primary' ABI for the device, corresponding to the machine
code used in the system image itself.
- an optional 'secondary' ABI, corresponding to another ABI that
is also supported by the system image.
For example, a typical ARMv5TE-based device would only define
the primary ABI as 'armeabi' and not define a secondary one.
On the other hand, a typical ARMv7-based device would define the
primary ABI to 'armeabi-v7a' and the secondary one to 'armeabi'
since it can run application native binaries generated for both
of them.
A typical x86-based device only defines a primary abi named 'x86'.