当前位置:网站首页>Talking about the CPU type of anroid device and the placement directory of so files

Talking about the CPU type of anroid device and the placement directory of so files

2022-07-23 13:42:00 iningwei

In the early Android The system almost only supports ARMv5 Of CPU framework . Now there are seven kinds :ARMv5,ARMv7 ( from 2010 From the year onwards ),x86 ( from 2011 From the year onwards ),MIPS ( from 2012 From the year onwards ),ARMv8,MIPS64 and x86_64 ( from 2014 From the year onwards ), Each of these CPU Architecture is associated with one ABI.

ABI namely Application Binary Interface, The binary interface is defined ( such as so file ) Interaction rules , To apply to different CPU. stay Android On the system , every last CPU Architecture corresponds to one ABI.

Android ABI

Android At present, the following seven are supported ABI:armeabi、armeabi-v7a、arm64-v8a、x86、x86_64、mips、mips64. Mainstream ABI Include :

  • armeabiv-v7a: The first 7 Generation and above ARM processor .2011 year 15 Most of the production after the month Android All the devices use it
  • arm64-v8a: The first 8 generation ,64 position ARM processor , Few devices , samsung Galaxy S6 Is one of them
  • armeabi: The first 5 generation 、 The first 6 Generation ARM processor , Early mobile phones used more
  • x86: Flat 、 Simulators are used a lot (2011 From the year onwards )
  • x86_64: 64 A bit of a flat (2014 From the year onwards )

mips and mips64 Rarely used , You can ignore

NDK

NDK What is it ? When your Android Used in Engineering C/C++ Code will be used NDK This development kit is used for development .

NDK namely Native Development Kit, Belong to Android, And Java No direct connection , Is a group that allows you to Android Rapid development in application C/C++ Dynamic library , And automatically so Packaged with the application into apk.NDK yes Android To realize JNI The means of ,JNI namely Java Native Inteface bring Java With other local languages ( Such as C/C++) Interact .

NDK I used to support mips,mips64,armeabi, But in NDK r17 Removed the for these ABI Support for .

because NDK Forward compatible ( front ,forward, future ), Recommended app Of minsdkVersion Corresponding compilation platform , Not the latest .

ABI And CPU

majority CPU All support multiple ABI, But for the best performance , Best use CPU The main ABI. As there are many ABI( such as so file ), Will install the best ABI, Others will not be installed .

64 Bit device (arm64-v8a, x86_64, mips64) Be able to run 32 Bit so library . But in order to 32 Bit mode runtime , Will be lost for 64 Bit optimized performance characteristics (ART, WebView, Media, etc.).

Many devices support more than one ABI, for example ARM64 and x86 The equipment can also run at the same time armeabi-v7a and armeabi The binary package of . But it is better to provide binary packages for specific platforms , In this case, there is one less simulation layer ( for example x86 Simulate on the device arm Virtual layer of ), For better performance ( Thanks to recent architecture updates , For example, hardware fpu, More registers , Better vectorization, etc ).

x86 On the device , choice ABI The priority of the

1,libs/x86 If it exists in the directory .so Word of the file , Will be installed .
2, If it doesn't exist , Will choose armeabi-v7a Medium .so file .
3, If it doesn't exist , select armeabi In the directory .so file .

arm On the device CPU yes arm64-v8a,ABI The priority of the svg

1, If it's a cell phone CPU yes arm64-v8a, Preference arm64-v8a Medium .so file .
2, If it doesn't exist , Will choose armeabi-v7a Medium .so file .
3, If it doesn't exist , select armeabi In the directory .so file .

arm On the device CPU yes armeabi-v7a,ABI Priority tool

1, If it's a cell phone CPU yes armeabi-v7a, Preference armeabi-v7a Medium .so file .
2, If it doesn't exist , Will choose armeabi Medium .so file .

so Where should the document be placed

To configure so The advice of

in the light of armeabi and armeabi-v7a Two kinds of ABI

Method 1: because armeabi-v7a Instruction set compatibility armeabi Instruction set , So it is acceptable to lose some application performance , At the same time, I don't want to keep two copies of the Library , You can remove armeabi-v7a Directory and the library files under it , Only keep armeabi Catalog ; such as Apk Use third party's so Only armeabi This kind of ABI when , Consider removing Apk in lib Under the table of contents armeabi-v7a Catalog .

Method 2: stay armeabi and armeabi-v7a Put one copy in each directory so.

in the light of x86

Currently on the market x86 Model , For compatibility arm Instructions , Basically, they are built-in libhoudini modular , That is, binary transcoding support , This module is responsible for ARM The command is converted to x86 Instructions , So if it's out of Apk Package size considerations , And it can accept some performance loss , You can choose to delete x86 The library catalog ,x86 Under the configuration of armeabi The directory so Libraries can also be loaded and used normally .

in the light of 64 position ABI

If App Developers intend to support 64 position , that 64 Bit so Put it all , Otherwise, you can choose not to compile separately 64 Bit so, All use 32 Bit so,64 Bit models support... By default 32 position so Loading . such as Apk Use third party's so Only 32 position ABI Of so, Consider removing Apk in lib In the catalog 64 position ABI subdirectories , Guarantee Apk Normal use after installation .

Current general practice

because mips The market share is very low ,x86 It's compatible again armeabi, So just support arm The architecture can , and arm in arm64-v8a Of cpu The architecture is also downward compatible armeabi-v7a And armeabi,arm-v7a The architecture is also compatible armeabi . So it seems that you only need to use armeabi It can cover almost all models on the market , But only using armeabi There are more than performance problems , In some old equipment, there is no guarantee crash.
At present, the recommended practice is to only support armeabi and armeabi-v7a, Ensure that .so The number of documents is consistent , This can ensure compatibility and minimize apk Volume . For only armeabi Third party of version .so, Make a copy of the original to armeabi-v7a Folder .

Other

Native Libs Monitor This application can help us understand what is installed on the mobile phone APK What's used .so file , as well as .so Which function libraries or frameworks do the files come from .

原网站

版权声明
本文为[iningwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230636089229.html