Official Android Technical Documentation translation-Apk splitting mechanism, androidapk

Source: Internet
Author: User

Official Android Technical Documentation translation-Apk splitting mechanism, androidapk

This article is translated from the official androd technical document Apk Splits. Original address: http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits.

URL: http://blog.csdn.net/maosidiaoxian/article/details/41692535. Indicate the source for reprinting. If any translation error occurs, please correct it.


Apk Splits

Directory

  1. 1Introduction
  2. 2Split by screen Density
  3. 3Split by ABI
  4. 4Supported Variant API & Version Code
Introduction: Compared with flavors, the split mechanism allows applications to build multiple apk files in some forms more effectively. Multi-apk only supports the following types
  • Screen Density
  • ABI
The new splitting mechanism is used to build the hdpi version and mdpi version of the same application, which can share many tasks (such as javac, dx, proguard ). In addition, it is considered a single variant, and the same test program will be used to test each multi-APK.
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 splitting Exclude: By default, all screen density is included. You can remove some density. Include: Screen density to be included Reset (): Reset the screen density list to contain only one empty string (this can be achieved in IncludeWhich screen density can be used together, rather than the screen density to be ignored) CompatibleScreens:List of compatible screens. This will be injected into the matched <compatible-screens> <screen> node in manifest. 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 codeext. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.