“This is the first day of my participation in the Gwen Challenge in November. See details of the event: The last Gwen Challenge in 2021”.

Like attention, no more lost, your support means a lot to me!

๐Ÿ”ฅ Hi, I’m Chouchou. GitHub ยท Android-Notebook has been included in this article. Welcome to grow up with Chouchou Peng. (Contact & Group entry on GitHub)


preface

  • Recently, major App markets are pushing to support 64-bit architecture. Does your App already support 64-bit architecture?
  • In this article, I’ll walk you through the process of adapting a 64-bit architecture. It will also give you a basic understanding of the ABI and bring you my Gradle plugin EasyPrivacy to help you detect 64-bit adaptation problems in your projects. Please be sure to like and follow if you can help, it really means a lot to me.

directory


1. An overview of the

1.1 Relationship between CPU and ABI

CPU architectures are CPU specifications defined by CPU vendors. Currently, the mainstream CPU architectures are divided into two categories:

  • Complex instruction set (CISC) : e.g. Intel and AMD X86 architecture;
  • Compact Instruction set (RISC) : For example, IBM PowerPC architecture and ARM architecture.

The Application Binary Interface (ABI), which defines the interaction between machine code and the operating system, should be understood as a specification rather than as an Interface source entity. See the Android ABI — official documentation for the information contained in the ABI

1.2 ABI supported by Android

Different Android devices use different cpus, and different cpus support different ABI. Currently, Android devices support the following ABI types:

ABI describe
armeabi The 5th and 6th generation OF ARM processors have basically retired from the historical stage
armeabiv-v7a The 7th generation and above ARM processors are gradually retiring from the stage of history
arm64-v8a Eighth-generation, 64-bit ARM processors are currently the mainstream
x86 / x86_64 It’s usually a simulator

The ABI supported by different cpus is as follows:

armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64
ARMv5 /

ARMv6
โœ”
ARMV7 โœ” โœ”
ARMV8 โœ” โœ” โœ”
X86 โœ” โœ” โœ”
X86-64 โœ” (Not supported) โœ” โœ”
MIPS โœ”
MIPS64 โœ” โœ”

Note: A list of ABIs supported by the device is available in build. SUPPORTED_ABIS, and the list is sorted by preference.

1.3 Primary and secondary ABI

Each CPU architecture has a primary ABI and (optional) compatible secondary ABI, and 64-bit cpus are compatible with the 32-bit ABI (for example, x86_64 is compatible with x86 and not vice versa). It is important to note that best performance is achieved using the main ABI (such as x86-compatible ArmeABI), which is the root cause of the application market’s push for 64-bit architecture adaptation.


2. Adapt the 64-bit architecture for Android devices

2.1 Time nodes for 64-bit architecture

Overseas app markets have been pushing for 64-bit architecture adaptation for 19 years. As of August 1, 2019, apps released on Google Play must support 64-bit architecture. As for the domestic app market, the approximate time nodes are as follows (take Xiaomi, VIVO and OPPO as examples) :

  • By the end of December 2021, applications released to the app market must support 64-bit architecture;
  • By the end of August 2022, only 64-bit versions of APK will be accepted for 64-bit hardware systems;
  • By the end of December 2023, hardware will only support 64-bit APK,

2.2 ABI Management of Android

When the application is installed, the PMS service scans the APK files to find the SO files of the main ABI types in the APK:

lib/<primary-abi>/lib<name>.so
Copy the code

If not, the APK file will be searched for the so file in the auxiliary ABI type:

lib/<secondary-abi>/lib<name>.so
Copy the code

When the look-ups are complete, PMS copies them to the so library path in the app directory (for example: /data/app/[packagename]/lib/arm64) and executes them to system.loadLibrary (…) when the application runs. Is loaded into memory. If no matching so file is found, the installation process is not interrupted, but it crashes at run time.

The process of loading so files has been discussed in the article “Talking about the process of loading and unloading the SO library”. You can go back and look at the main source: dexPathlist.java

— Picture quoted from iQiyi technical team

As you can see, what exactly does adapting a 64-bit architecture do? The bottom line is to provide the highest-performing main ABI SO files for your system. The focus of the upper application is to provide 64-bit SO files, which we can break down into three parts:

  • 1. Retrieve so files that do not support 64 bits (EasyPrivacy plugin)
  • 2. Build 64-bit APK
  • 3. Distribute 64-bit APK

3. EasyPrivacy plug-in retrieves so files with one click

There are two methods for retrieving APK so files that do not support 64 bits. Please refer to the official documentation:

  • 1. Analyze by APK analyzer (drag APK directly onto Android Studio);
  • 2. Decompress APK and passgrepCommand to analyze.

These two methods can basically meet the requirements, but it takes too much time to operate and cannot directly indicate which component the so file is integrated by (for example, pusher. Aar integrates libc++_shared.so internally, and APK knows that the so file is from pusher.) In order to quickly retrieve so files that do not support 64 bits in the project, I have helped you implement it as an EasyPrivacy plug-in. Source code address: github.com/pengxurui/E…

3.1 Adding a Dependency

  • 1. Rely on EasyPrivacy plugin

Declare the remote repository in project-level build.gradle and rely on the EasyPrivacy plug-in:

Project level build. Gradle

buildscript { repositories { ... Maven {url "https://jitpack.io"}} dependencies {... The classpath 'com. Making. Pengxurui: EasyPrivacy: v1.0.2}}Copy the code
  • 2. Apply EasyPrivacy plug-in

Apply EasyPrivacy plugin to build.gradle at application or module level:

build.gradle

apply plugin: 'com.pengxr.easyprivacy'
...
Copy the code

After Sync Gradle is executed, you can see a new detection task in the Gradle panel, located in the Privacy task group:

3.2 Running the Support 64-bit ABI

Perform the support 64-bit ABI task to retrieve the SO files in the Gradle dependency tree of this module and filter out the SO files that have not completed the 64-bit adaptation. For example, a libc++_shared.so file of type armeabiv-v7a exists in the project, but the corresponding 64-bit arm64-v8a type is not provided. Add tooltips to groups so in armeabiv-V7A, but not in arm64-V8a:

3.3 Analyzing Logs

The following is the log output in the SAMPLE module:

. > Configure project :sample ... > Task :sampleLib:copyReleaseJniLibsProjectOnly UP-TO-DATE > Task :sample:mergeReleaseNativeLibs UP-TO-DATE > Task :sample:support 64-bit abi EasyPrivacy => Support 64-bit abi start. EasyPrivacy => so: / Users/pengxurui /. Gradle/caches/transforms - 2 / files - 2.1/297 c6c751393f4fc48ae19ba461e118a/openDefault - 4.2.7 / jni/armeabi - v7 a/libweibosdkcore.so EasyPrivacy => so: / Users/pengxurui /. Gradle/caches/transforms - 2 / files - 2.1/297 c6c751393f4fc48ae19ba461e118a/openDefault - 4.2.7 / jni/x86 / libwei bosdkcore.so EasyPrivacy => so: / Users/pengxurui /. Gradle/caches/transforms - 2 / files - 2.1/297 c6c751393f4fc48ae19ba461e118a/openDefault - 4.2.7 / jni/armeabi/li bweibosdkcore.so EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sample/build/intermediates/merged_jni_libs/release/out/armeabi-v7a/libbsdi ff.so EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sample/build/intermediates/merged_jni_libs/release/out/x86/libbsdiff.so EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sample/build/intermediates/merged_jni_libs/release/out/armeabi/libbsdiff.s o EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sampleLib/build/intermediates/library_jni/release/jni/armeabi-v7a/libgetui ext3.so EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sampleLib/build/intermediates/library_jni/release/jni/armeabi-v7a/libc++_s hared.so EasyPrivacy => so: /Users/pengxurui/workspace/public/EasyPrivacy/sampleLib/build/intermediates/library_jni/release/jni/arm64-v8a/libgetuiex t3.so EasyPrivacy => armeabi size: 2 EasyPrivacy => armeabiv-v7a size: 4 EasyPrivacy => arm64-v8a size: 1 EasyPrivacy => x86 size: 2 EasyPrivacy => x86_64 size: 0 EasyPrivacy => mips size: 0 EasyPrivacy => mips_64 size: 0 so in armeabi, but not in arm64-v8a: [opendefault-4.2.7 :libweibosdkcore.so] [:libbsdiff.so] so in armeabiv-v7A, but not in arm64-V8A: [opendefault-4.2.7 :libweibosdkcore.so] [:libbsdiff.so] [:libc++_shared.so] so in x86, but not in x86-64: [opendefault-4.2.7 :libweibosdkcore.so] [:libbsdiff.so] so in MIPS, but not in mips-64:Copy the code

[opendefault-4.2.7 :libweibosdkcore.so], [:libbsdiff.so], [:libc++_shared.so] the three so files do not provide arm64-v8a type. This is where you need to adapt.

Opendefault-4.2.7 is the POM information of the AAR where the SO file is located. You can judge the SDK to be adapted according to this information. In addition, things like libbsdiff.so are so files that are directly integrated into the project.


4. Build 64-bit APK

With the adaptation done, you now need to build a 64-bit APK. Depending on the requirements of the app market, you need to build three packages:

  • 1. 32-bit packages
  • 2. 64-bit packages
  • 3. 32/64-bit packages (including both 32-bit and 64-bit SO files)

4.1 the NDK. AbiFilters configuration

So files that need to be packaged into APK can be filtered through the ndK. abiFilters configuration. For example, the following configuration will package armeabI-V7A and ARM64-V8A SO files into APK:

Application level build. Gradle

android {
    ...
    defaultConfig {
        ...
        ndk {
            abiFilters "armeabi-v7a","arm64-v8a"
        }
    }
}
Copy the code

4.2 splits configuration

The NDK. abiFilters configuration can pack all the so files of the supported ABI into APK, with the disadvantage of increasing the package size. Our market has the ability to distribute both 32-bit and 64-bit APK packages separately, and we have access to that field. For example, the following configuration packages each ABI type separately. When the universalApk is true, an additional APK containing all ABI types is built.

android {
    ...
    defaultConfig {
        ...
        splits {
            abi {
                enable true
                reset()
                include 'armeabi-v7a', 'arm64-v8a'
                universalApk false
            }
        }
    }
}
Copy the code

5. To summarize

EasyPrivacy framework source CODE I have put on Github, source address: github.com/pengxurui/E… Sample Demo, you can run it directly. Welcome criticism, welcome Issue~

How often have you received privacy emails from app marketplaces in recent months? Yes, while Chinese users’ awareness of privacy has been strengthened, the rectification of App privacy standards is also being tightened step by step. We will eventually have to repeat the same path that we have gone through overseas (Google Play/App Store).

We will find that privacy rectification is an unavoidable problem for every App, which has common characteristics. I want to make EasyPrivacy, a Gradle plug-in specially for privacy rectification, to help developers quickly find privacy problems in projects. Is there a similar tool in the market? Can you share it with me? Or you can mention the most annoying rectification issues (” Feature! “).


The resources

  • 64-bit architecture supported – Official documentation
  • Build multiple APKs — official documents
  • Android ABI — Official documentation
  • Iqiyi App Architecture Upgrade road — 64-bit adaptation Exploration and Practice — by iQiyi Technology product team
  • Android for 64-bit architecture — callmepeanut

Creation is not easy, your “three lian” is chouchou’s biggest motivation, we will see you next time!