当前位置:网站首页>The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores

The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores

2022-06-25 09:52:00 seevc

One 、 reason

Recently received an upgrade from Xiaomi and other app stores 64 Notification of bit architecture , The general content is as follows :
For better promotion APP Performance experience , Reduce APP Power consumption impact , Xiaomi app store and OPPO The app store 、vivo App stores jointly promote the domestic android ecosystem 64 Bit architecture upgrade support . The industry adaptation rhythm is as follows :

  • 2021 year 12 End of month : Existing and new applications / game , You need to upload a file containing 64 The study of the inclusion APK package ( Support double package in shelf , and 64 Bit compatible 32 Two forms of bit , No longer receive only support 32 Bit APK package )
  • 2022 year 8 End of month : Hardware support 64 A system of , Will receive only those with 64 A version of the APK package
  • 2023 end of the year : The hardware will only support 64 position APK,32 Bit application cannot run on the terminal

After receiving the notification, I checked my app and found that only 32 An architecture (armabi, In order to reduce the Apk Inclusion size ). Since the major app stores have mandatory requirements for this , So we should aim at 64 The bit architecture is out of the package .

### Two 、 Two kinds of schemes
From the app store, you can see that uploading is only supported 64 Bit structured APK package , So consider supporting 32 Bit and 64 Bits packed separately , This will ensure APK size , And meet the needs .
After research, it is found that there are two ways to realize .
##### Scheme 1
stay android Add... Under the code block splits Code block , Then add abi Code block and configure to support ABI list .
Let's take an example :

andoird{
    ...
    splits{
        //  Press ABI Configure multiple APK.
        abi {
            enable true
            reset()
            include "armeabi-v7a", "arm64-v8a"
            universalApk false
        }
    }
}

Now let's explain the meaning of the related configuration attributes .
stay Gradle DSL Press ABI Configure multiple APK, There are several properties :

  • enable, Whether to enable the... According to the configuration ABI package , Default false, That is, do not open ;
  • exclude, Appoint Gradle Which... Should not be targeted ABI Generate separate APK, Configure... As a comma separated list , There's no need to be with reset()、include Simultaneous configuration ;
  • reset(), Clear the default ABI list , Only with include Elements are used in combination , To specify what you want to add ABI;
  • include, Packaging should support ABI list , Specify... As a comma separated list Gradle What should be targeted ABI Generate APK. Only with reset() Use a combination of , To specify the exact ABI list ;
  • universalApk, Whether it is necessary to type an include include All configured ABI Generic package for , The default is false, If set to true, Then you will press ABI Generated APK outside ,Gradle It will also generate a generic APK

About reset() Important details of
stay Android Plugin for Gradle 3.1.0 And above versions are no longer supported ABI Yes :mips、mips64 and armeabi, Because in NDK R17 Version and above no longer support these ABI.
Higher version Gradle The plug-in supports by default ABI by :armeabi-v7a、arm64-v8a、x86、x86_64.
reset() Remove the ABI The list is just these , So when not in use reset() when , These architectures are included by default .

The following is to support :armeabi-v7a、 arm64-v8a The configuration mode of the instance
use exclude The way

andoird{
    ...
    splits{
        //  Press ABI Configure multiple APK.
        abi {
            enable true
            // According to the default supported abi, The following two items are excluded , That's all armeabi-v7a、arm64-v8a
            exclude "x86", "x86_64"
            universalApk false
        }
    }
}

use reset() and include combination

andoird{
    ...
    splits{
        //  Press ABI Configure multiple APK.
        abi {
            enable true
            reset()
            include "armeabi-v7a", "arm64-v8a"
            universalApk false
        }
    }
}

use Build -> Generate signed Bundle/APK Or run assembleRelease pack , You can perform a packaging operation to automatically generate multiple Apk package .

That's it. I'll finish the program , Doesn't it look very simple . So let's move on .

##### Option two
Refer to subcontracting to be familiar with Android Developers should think about it very quickly productFlavors, you 're right , The second option is to use productFlavors Realized .
adopt productFlavors The code block can realize multi-dimensional variants of the product , such as :vip He Fei vip package 、 The version number is different , Channel package, etc

It's described in the official documents :“ In some cases , You may want to combine the configurations of multiple product variants . for example , You may want to base your API Grade “full” and “demo” Product variants create different configurations . So , You can use Android Plugin for Gradle Create multiple groups of product variants as variant dimensions . When building applications ,Gradle The product variant configuration in each variant dimension you define and build Type configurations are grouped together , To create the final build variant .Gradle Product variants belonging to the same variant dimension will not be combined .”

The following still supports armeabi-v7a and arm64-v8a For instance , First look at the configuration instance :

android{
        ...
        flavorDimensions "teacher"
        productFlavors{
            armabi_v7a{
                ndk {
                    abiFilters  "armeabi-v7a"
                }
                dimension "teacher"
            }
            arm64_v8a{
                ndk {
                    abiFilters "arm64-v8a"
                }
                dimension "teacher"
            }
        }
}

Configuration related attribute interpretation

  • flavorDimensions, Define product dimensions , Multiple dimensions can be defined , Separate with commas , The configured value corresponds to productFlavors Medium dimension Property value ;
  • among armeabi_v7a and arm64_v8a Names can be defined by themselves ;
  • ndk, The configuration code block is the package to include ABI;
  • abiFilters, Define what packaging supports arm framework , Support configuration of multiple , Separate with commas , Such as :"armeabi-v7a","x86"
  • dimension, Dimension of the product , Value has to be with flavorDimensions The values configured in are consistent , Otherwise, such errors will occur :The flavor 'flavor_name' is not assigned to a flavor dimension

explain
When configuring packaging in this way , It needs to be packed one by one , as follows :
Build->Generate signed Bundle/APK Schematic diagram of mode packaging :
image.png

perhaps Gradle perform Task The way :
image.png

3、 ... and 、 Comparison of the two schemes

The way advantage shortcoming
splits Simple configuration , A single package can generate multiple APK Unable to support ABI The way of combination , Such as :armeabi-v7a and x86
productFlavors Support multiple ABI Pack together , Relatively flexible 1. comparison splits The way is a little complicated , Need to pass through flavorDimensions Define dimensions
2. Packaging is a little complicated , It is not possible to generate multiple by packaging at once APK

Through comparison, we found that :
1. if APP Only one kind of CPU framework , Then mode 1 is more appropriate ;
2. if APP At the same time, support arm and x86 framework , Then mode 2 is more appropriate ;

### Reference resources Android Official documents
in the light of ABI Configure multiple APK
Combine multiple product variants and variant dimensions

原网站

版权声明
本文为[seevc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200547583289.html