Android multi-CPU architecture adaptation starts with

Source: Internet
Author: User

Summary: When you do a project, you often use the so file. For example, with the high-D map, the SDK contains Armeabi, armeabi-v7a, ARM64-V8A, x86 and other folders, usually with the same name, the same number of so files. In the actual use of the process, the problems caused by these so files are indeed many, but also difficult to solve. Write down this article, hope to encounter related problems, can have a general idea.


Noun Analysis:

Ndk:native Development Kit

Jni:java Native Interface

Abi:application binary Interface Application binary interface


Android Studio uses so library

1. Use the same way as eclipse to create a new Armeabi directory in the Libs directory

A statement that specifies the JNI library directory needs to be added to the Build.gradle

sourcesets {

Main.jniLibs.srcDirs = [' libs ']//specifies the storage directory where the Libs is JNI

}

2, use as the default location: Src/main/jnilibs

Create a new jnilibs directory directly under Src/main/, and place directories such as Armeabi in this directory

Note: As can right-click a new jnilibs directory under the same directory, but the directory is not a compiled library file directory, but a directory of local code files that are not compiled (this refers to the JNI directory with Java peers, where the CPP code is placed)


Android supported CPU architectures (currently seven types)


Armeabi 5th-generation arm v5te, using software floating point arithmetic, compatible with all ARM devices, versatility, slow speed
armeabi-v7a 7th Generation ARM V7 with advanced extended functionality using hardware floating-point arithmetic
arm64-v8a 8th generation, 64-bit, contains AArch32, AArch64 two execution states corresponding 32, 64bit
x86 Intel 32-bit, typically used for tablet
x86_64 Intel 64-bit, typically used for tablet
Mips Less contact
Mips64 Less contact


Compatibility Check at installation:

Once installed into the system, so files are extracted in the data/app/com.xxxxxxxx.app-x/lib/directory (version 5.0),/data/app-lib/ Directory (version 4.2), where Armeabi and armeabi-v7a generate the arm directory, ARM64-V8A generates ARM64 directories.

When installing the app, if the app uses so files and there are no so files for the native CPU architecture, the following error will be reported:

Installation failed with message Install_failed_no_matching_abis.

For example, there must be a x86 version of the so folder on the x86 emulator. Otherwise, the installation will not succeed.


Run-time compatibility check:

1, check the target directory for the existence of so library files

2. Check if the existing so file conforms to the current CPU architecture.

For the situation one, the general evasion of the practice is: to ensure that the Jnilibs directory under the x86, x84_64, Armeabi, armeabi-v7a, arm64-v8a and other directories under the file name number is consistent.

For example: A, B, C three third-party libraries are used in the project. Where A and b provide Armebi and arm64-v8a versions of the library file, and C provides only the Armebi, armebi-v7a version of the library file. This time only can delete the original arm64-v8a directory, keep the Armeabi directory, General arm64 phone can be compatible with the Armeabi version of the library. or copy a Armeabi so file into the missing directory (recommended).


Generate so file:

NDK Cross Compile When selected App_abi: = Armeabi x86 ... You can generate so files that support the corresponding chip. App_abi: = All generates support for all chip instruction sets (currently seven) so files.


Android load so file rules:

When you provide only the Armeabi directory, armeabi-v7a, ARM64-V8A architecture program will go to Armeabi, and when you also provide armeabi-v7a, armeabi-v8a directory, and there is no corresponding so library , the system will not go to armeabi inside look for, directly can not find an error. the same is true for other platforms. Here I stepped on a lot of pits, remember.

In general, some of the more well-known third-party libraries provide Armeabi, ARMEABI-V7A, x86, three types of so files, while the three versions of the app can be run on all models. In addition, more and more SDKs will be available in the arm64-v8a version. Projects that contain only Armeabi can also run on all devices.


Practical cases:

I used Armeabi, arm64-v8a two types in my project, and when I needed to use a third-party voice library, I found that only Armeabi, armeabi-v7a two types of so files were available, and my phone was arm64-v8a. So only use the so file inside the arm64-v8a, when the use of the Voice library can not find the corresponding so library, will be error. There are two ways to solve this theory:

First, delete all arm64-v8a, keep only Armeabi, all use the most compatible version, but also run the slowest.

Second, copy the Armeabi version of the Voice library to arm64-v8a. A single so file uses the Armeabi compatible version.


Summarize:

    1. When you use the so file, ensure that the number of file names in each subfolder is consistent.

    2. for third-party libraries that only provide Armeabi, copy a armeabi so file to the missing directory; keep only the Armeabi directory (not recommended)


Reference Documentation:

A long-standing pit related to. so

Android for so file compatibility issues with ARM64-V8A, armeabi-v7a, Armeabi, x86

What you need to know about the. So file for Android


This article is from a "sword Siege" blog, please make sure to keep this source http://weijiancheng.blog.51cto.com/10190955/1893473

Android multi-CPU architecture adaptation starts with

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.