Compatibility and adaptation of Android so files

Source: Internet
Author: User

When developing an Android application, sometimes the Java layer encoding does not meet the implementation requirements, it needs to be implemented in C + + to generate so files, and then use System.loadlibrary () load to make calls, this is the implementation of the JNI layer. Common scenarios such as: Encryption and decryption algorithm, audio and video codec and so on. When generating so files, you need to consider adapting to different phone CPU architectures on the market and generating so files that support different platforms for compatibility. Currently Android supports seven different types of CPU architectures, namely: Armv5,armv7 (since 2010), x86 (since 2011), MIPS (from 2012 onwards), Armv8,mips64 and x86_64 (from 2014). If you want to be perfectly compatible with all types of phones, it is theoretically possible to place the so file for each architecture platform in the Libs directory.

This way, you can be compatible with all models, but your project size will become very large. Is it necessary to bring in so many so files to be compatible? The answer is in the negative.

So (CPU) compatibility

For the CPU, different architectures do not necessarily mean incompatible, according to the current Android support seven different types of CPU architecture, the compatibility features can be summarized as follows:

    • Armeabi equipment only compatible with Armeabi;
    • ARMEABI-V7A equipment compatible with armeabi-v7a, Armeabi;
    • ARM64-V8A equipment compatible with arm64-v8a, armeabi-v7a, Armeabi;
    • X86 equipment compatible with X86, Armeabi;
    • X86_64 equipment compatible with x86_64, X86, Armeabi;
    • MIPS64 equipment compatible with MIPS64, MIPS;
    • MIPS is compatible with MIPS only;

According to the above compatibility summary, we can also get some rules:

    • Armeabi's so file can basically be said to be a balm, it can run in addition to MIPS and MIPS64 devices, but on non-Armeabi devices running performance or loss;
    • The 64-bit CPU architecture always backwards compatible with its corresponding 32-bit instruction set, such as: x86_64 compatible X86,ARM64-V8A compatible ARMEABI-V7A,MIPS64-compatible MIPS;

About the compatibility of so the law is introduced here, the following talk about the adaptation work.

The adaptation of So

From the current mobile CPU market share data look, ARM architecture almost monopoly, so unless your users are very special, you can almost regardless of the individual compiled into the X86, x86_64, MIPS, MIPS64 architecture so file. With the exception of these four architectures, there are three different types of Armeabi, armeabi-v7a, arm64-v8a, which will increase the volume of the installation package for an application with a large number of so files.

In view of the above situation, we can apply the equipment distribution and market situation again to choose, if your application still has a lot of armeabi type of equipment , you can consider to keep only the Armeabi directory of so files (balm characteristics). However, although Armeabi can be compatible with a variety of platforms, there are still some operations in armeabi-v7a, arm64-v8a to use the Armeabi so file, the performance will be very poor, so it should be the corresponding platform architecture of so file. Note that this is not to bring a set of so files to a different directory, but rather the performance difference between a armeabi-v7a, arm64-v8a platform under the so file into the Armeabi directory, and then through the code to determine the device's CPU type, And then load its corresponding schema of so file, many manufacturers of the application is to do so. In the case of Lib, although only armeabi a directory, but the directory of files still placed in the V5, v7a schema so file, to deal with the compatibility of some performance problems.

As far as market share is concerned, most of the equipment is already armeabi-v7a, arm64-v8a, you can also consider preserving only the armeabi-v7a architecture of so files, so as to achieve better performance results.

Summarize

The above is a summary of the compatibility of so files, if there are errors, welcome to point out.

Compatibility and adaptation of Android so files

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.