Detailed explanation of Android JNI series: Generating library files for specified CPUs

1. Premise

This time we mainly understand the CPU architecture type of Android and how to specify which type of library file to generate when using the CMake tool.

As shown in the figure above, we have used the CMake tool to generate dynamic library files for four CPU architectures by default: arm64-v8a, armeabi-v7a, x86, x86_64, which respectively correspond to support for four different CPU types.

 As shown in the figure above, different mobile phones use different CPUs, and different CPUs support different instruction sets. Each instruction set has a corresponding binary interface ABI (arm64-v8a, armeabi-v7a, x86, and x86_64 are the four ABI types) , which is a binary library file. Among them, arm64-v8a and armeabi-v7a are commonly used on mobile phones, and x86 and x86_64 are more commonly used on tablets and virtual machines.

1. ABI compatibility of commonly used CPUs:

 If the CPU architecture of our mobile phone is armv7, we can only configure armeabi-v7a in the project, which is compatible with mobile phones with three CPUs: armv7, armv8, and x86. This can save the size of the installation package, which is the benefit of compatibility.

2. Use the adb command to check the CPU mechanism of the phone

adb shell

cat /proc/cpuinfo

 2. How to configure and generate library files for specified CPUs

Two ways to configure in gradle:

1. Add the ndk closure under the defaultConfig closure under the android closure, as shown below: This can be used for cmake and ndk-build

 2. Configure in the cmake configuration of gradle: This is only applicable to the cmake tool

 After compiling in these two ways, files in the corresponding directories are generated (supports multiple additions with commas: abiFilters "arm64-v8a", "x86")

 

Guess you like

Origin blog.csdn.net/sunbinkang/article/details/132528551