Android, Flutter package APK for different CPU architecture packages (v7a, v8a, x86)

By default, the Apk packaged by Android and Flutter contains all the architectures, so the volume of the typed apk is a bit larger than that of the single-architecture apk.

At this time, we need to type out different architecture packages separately.

Architecture

Generally speaking, x86 stands for 32-bit CPU, and x64 (or x86-64) stands for 64-bit CPU.

In Android, support for proprietary cpu architecture is also Application Binary Interface (ABI).

ABIs supported in the Android developer official website documentation.
insert image description here

armeabi-v7a

This ABI applies to 32-bit ARM-based CPUs, and most of the CPUs of Android phones before 2016 use this architecture.

arm64-v8a

This ABI is suitable for ARMv8-A-based CPUs and supports 64-bit AArch64 architecture. Generally, starting from 2016, the CPU architecture of mainstream Android phones is arm64.

x86

This ABI supports the X86 architecture, and CPUs like Intel and AMD are based on this architecture.
During the period of 2012-2016, in order to catch up with the wave of the mobile Internet, Intel and Nvidia specially launched X86-based CPUs for Android phones and tablets, but unfortunately they all failed. It is generally not necessary to adapt this architecture now, unless the APK needs to be installed on an Intel tablet.

x86_64

This ABI supports CPUs of x86-64-bit architecture. Ditto

For these architectures, Android is mipsno mips64longer supported since (corresponding to gradle 4.4), because starting from NDK r17, these ABIs are no longer supported as targets.armeabiAndroid Plugin for Gradle 3.1.0

APK subpackage

Android

In the module-level build.gradle file, add the splits module in the android code block.
The basic configuration is as follows.

android {
  ...
  splits {

    // 基于不同的abi架构配置不同的apk
    abi {

      // 必须为true,打包才会为不同的abi生成不同的apk
      enable true
     
      // 默认情况下,包含了所有的ABI。
      // 所以使用reset()清空所有的ABI,再使用include指定我们想要生成的架构armeabi-v7a、arm-v8a
      reset()

      // 逗号分隔列表的形式指定 Gradle 应针对哪些 ABI 生成 APK。只与 reset() 结合使用,以指定确切的 ABI 列表。
      include "armeabi-v7a", "arm64-v8a"

      // 是否生成通用的apk,也就是包含所有ABI的apk。如果设为 true,那么除了按 ABI 生成的 APK 之外,Gradle 还会生成一个通用 APK。
      universalApk false
    }
  }
}

Flutter

After using the following commands, apks for three architectures, v7a, v8a, and x86-64, will be automatically generated.

flutter build apk --split-per-abi

The build location is build/app/outputs/flutter-apk/.
insert image description here

Guess you like

Origin blog.csdn.net/adojayfan/article/details/122107605