Official Android Technical Documentation translation-Apk splitting Mechanism
Apk Splits
Directory
- 1Introduction
- 2Split by screen Density
- 3Split by ABI
- 4Variant API & Version Code supports introduction to the splitting mechanism. Compared with flavors, this allows applications to build multiple apk formats more effectively. Multi-apk only supports the following types
- Screen Density
- ABI uses the new splitting mechanism to build the hdpi version and mdpi version of the same application, and can share many tasks (such as javac, dx, proguard ). In addition, it will be considered a single variant, and the same test program will be used to test each ?? Multiple APK files.
When you run the install or connectedCheck task on variant, Gradle automatically outputs the correct APK to each connected device.
If you want to make another type of multi-APK (defined here: http://developer.android.com/google/play/publishing/multiple-apks.html) You can also create Flavors (API-level multi-apk instance ), each variant has its own output. Split android by screen density {... splits {density {enable true exclude ldpi, tvdpi, xxxhdpi compatibleScreens 'small', 'normal', 'large ', 'xlarge '}}
Enable: Enable screen density splittingExclude: By default, all screen density is included. You can remove some density.Include: Screen density to be includedReset (): Reset the screen density list to contain only one empty string (this can be achieved inIncludeWhich screen density can be used together, rather than the screen density to be ignored)CompatibleScreens:List of compatible screens. This will inject the matched Node. This setting is optional.
Note that this will always generate a general APK containing all the screen density.
Example: densitySplit split android by ABI {... splits {abi {enable true reset () include 'x86 ', 'armeabi-v7a', 'mips 'universalApk true }}}
Enable: Enable the ABI splitting mechanism. Exclude: By default, all ABI items are included. You can remove some ABI items. Include: Indicates which ABI to include Reset (): Reset the ABI list to include only one empty string (this can be achieved in IncludeTo indicate which ABI to use, rather than which one to ignore) UniversalApkIndicates whether to package a general version (including all ABI ). The default value is false.
Example: ndkSanAngelesVariant API & Version Code supports warnings about obsolete APIs: Some methods contained in the current variant API have been moved to its outputs object. This method still exists, but if more than two outputs exist, the build will fail. They will be completely deleted in version 1.0. They are:
- Get/setOutputFile
- GetProcessResources
- GetProcessManifest
- GetPackageApplication/Library
- GetZipAlign method added on VariantOutput
- String getAbiFilter ()
- String getDensityFilter ()
- Task getAssemble ()
- String getName ()
- String getBaseName ()
- String getDirName
- Set/getVersionOverride // optional versionCode Rewriting
- Int getVersionCode () // returns the versionCode rewritten from the output, or the versioncode of variant.
Each generated APK must have different versionCode. Similar to traversing variants to set versionCode, You can traverse the outputs of variant and set its versionCodeOverride.
// Map for the version code ext. versionCodes = ['armeabi-v7a ': 1, mips: 2, x86: 3]
Import com. android. build. OutputFile
Android. applicationVariants. all {variant-> // assign different version code for each output variant. outputs. each {output-> output. versionCodeOverride = project. ext. versionCodes. get (output. getFilter (OutputFile. ABI) * 1000000 + android. defaultConfig. versionCode }}
If both flavors and splits are used to output multiple apk files, you should still use VariantOutput. setVersionCodeOverride (int), but you should calculate the versionCode in the split information (densityFilter and abiFilter) and variant information.