Android会自动加载设备的“最佳”.so文件吗?

时间:2011-11-14 07:35:11

标签: android architecture dynamic load

我正在编写一个需要一些JNI代码的应用程序。 这段代码涉及浮点处理,所以我希望它尽可能快。因此,我想支持ARM5和ARM7架构。在我的Application.mk中它说:

APP_ABI := all

...构建过程为ARM5,ARM7和x86编译模块。我验证了所有.so文件最终都在.apk文件中。

现在的问题是:Android会自动加载“最佳”.so文件,具体取决于它运行的平台吗?换句话说:它会在ARM5设备上加载ARM5模块吗?在ARM7设备上加载ARM7吗?

1 个答案:

答案 0 :(得分: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'.