## Build multiple APKs

First, the supported ABI

ABI management: Different Android phones use different cpus and therefore support different instruction sets. The ABI defines very precisely how the application’s machine code interacts with the system at run time. The ABI contains the following information:

  • The set of CPU instructions that machine code should use.
  • Byte order for runtime memory storage and loading.
  • The format of executable binaries, such as programs and shared libraries, and the types of content they support.
  • Conventions for parsing data between content and the system. These conventions include alignment restrictions and how the system uses the stack and registers when a function is called.
  • A list of function symbols available at run time for machine code – usually from a very specific set of libraries. 2. ABI classification:

Configure multiple APKs for different ABI cpus

Build Multiple APKs. Configure splites blocks in build.gradle of app module.

android {
   ......
    splits{
        abi {
            enable = true
            reset()
            include "armeabi"."armeabi-v7a"}}}Copy the code
  • Enable If you set this element to true, Gradle generates multiple APKs based on the ABI you define. The default value is false
  • Exclude specifies that the comma-separated list of ABIs does not generate a separate APK.
  • Reset clears the default list of the ABI. Used only in conjunction with the include element to specify the ABI to be added.
  • Include specifies that Gradle should generate a comma-separated list of THE APK’s ABI for it. The exact list of the ABI can only be specified in combination with reset().
  • UniversalApk if true, Gradle generates a universalApk in addition to per-abi APK. A generic APK contains the code and resources for all the ABI’s in a single APK. The default value is false. Please note that this option is only available in that Mono. abi block. When multiple APKs are built based on screen density, Gradle always generates a generic APK that contains code and resources for all screen densities.

2. Build Click Build > Build APK. Gradle creates an APK for each density or ABI into the project build/ Outputs/APK/directory.

Three, configure multiple APK for screen density

1, configuration,

android {
  ...
  splits {
    density {
      enable true
      exclude "ldpi"."xxhdpi"."xxxhdpi"
      compatibleScreens 'small'.'normal'.'large'.'xlarge'}}}Copy the code
  • Enable If you set this element to true, Gradle generates multiple APKs based on the screen density you define. The default value is false.
  • Exclude specifies that the comma-separated list of screen densities does not generate a separate APK. If you need to exclude some density that your application does not support.
  • Reset Clears the default list of screen densities. Used only in conjunction with the include element to specify the density to be added.
  • Include specifies that Gradle should generate a density list of APKs for it. The exact list of densities can only be specified with reset().
  • CompatibleScreens specifies a comma-separated list of compatible screen sizes. This injects a matching node into the manifest for each APK. 2. Build multiple APKs based on ABI and screen density
  splits {
    density {
      enable true
      reset()
      include "mdpi"."hdpi"
    }
    abi {
      enable true
      reset()
      include "x86"."x86_64"}}Copy the code