The relationship between Android's .so file, ABI and CPU

I. Introduction

Different Androiddifferent mobile phone use CPU, and different CPUdifferent instruction set support, CPUeach in combination with the instruction set has a unique application binary interface, that is ABI(全称:ApplicationBinary Interface).

Two, Android's CPU architecture

AndroidThe system currently supports the following seven different CPUarchitectures

CPU architecture description time
ARMv5 The 5th generation ARM v5TE, using software floating point calculation, compatible with all ARM devices, strong versatility, slow speed
ARMv7 The 7th generation ARM v7, using hardware floating point operations, with advanced extended functions Since 2010
x86 intel 32 bit, generally used for tablet Since 2011
x86_64 Intel 64 bit, generally used for tablets Since 2014
ARMv8 The 8th generation, 64-bit, contains AArch32, AArch64 two execution states corresponding to 32, 64bit Since 2014
MIPS Less contact
MIPS64 Less contact Since 2014

Three, the correspondence between CPU and ABI

CPU architecture (vertical)\API (horizontal) armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64
ARMv5 stand by
ARMv7 stand by stand by
x86 stand by stand by stand by
x86_64 stand by stand by stand by
ARMv8 stand by stand by stand by
MIPS stand by
MIPS64 stand by stand by

AndroidApplication support ABIdepending APKlocated lib/ABI目录in .so文件, which ABImay be the above-mentioned seven kinds of ABIa medium of.
When an application is installed on a device, only the files CPUcorresponding to the architecture supported by the device .sowill be installed.
Select ABIwhen there will be apriority, The use of different supported ABIwill show different performance.
For example, on the
x86 device, libs/x86目录if a .sofile exists in the file, it will be installed, if it does not exist, armeabi-v7athe .sofile in the file will be selected , and if it does not exist, armeabithe .sofile in the directory will be selected .
x86The device can run the ARMtype function library well, but there is no guarantee that it will 100%not happen crash, especially for old devices. The function library that the
64位device ( arm64-v8a, x86_64, mips64) can run 32位, but 32位runs in mode, and the version and components running on the 64位platform will lose the performance optimized for the purpose ( etc.).32位ARTAndroid64位ART,webview,media

Fourth, the information contained in a typical ABI

Use of a machine code CPUinstruction set.
2 The byte order of memory storage and loading at runtime.
3 The format of executable binary files (such as programs and shared libraries) and the types of content they support.
4 Various conventions used to resolve data between content and the system. These conventions include alignment restrictions, and how the system uses the stack and registers when calling functions.
5 List of function symbols available for machine code at runtime-usually from a very specific set of libraries.

Five, .so file naming convention

.soThe name must have liba prefix or apkunzip / install the phone when not put libs\API目录in .socopy to /data/data/com.你的应用包名/libthe next.

6. Storage location of .so files

The corresponding ABIbinary files (such as .sofiles), corresponding to put ABI目录in
1 Android Studio project
on jniLibs/ABI目录中(of course, can be achieved by build.gradlesetting file jniLibs.srcDirattributes specify your own)
as jniLibs/armeabi/libxxx.so
2 Eclipse project
on libs/ABI目录中(which is the ndk-buildcommand generated by default .sodirectory files )
Such as libs/armeabi/libxxx.so
3
AAR is located in the compressed package in the AAR compressed packagejni/ABI目录中 (the .sofile will be automatically included in the reference AARcompressed package APK)
such as jni/armeabi/libxxx.so
4 is the path in the APK and the
final APKfile lib/ABI目录中
such aslib/armeabi/libxxx.so

Guess you like

Origin blog.csdn.net/linxinfa/article/details/107683170