The Android manifest files merge those things

Source: Internet
Author: User

The apk file can contain only one androidmanifest.xml file, but the Android studio project may contain multiple files (introduced via BUILDSRC, imported libraries). Therefore, when building an app, the Gradle build merges all the manifest files into a single encapsulated apk manifest file.

Manifest file Consolidation Priority

Inventory Merge Tool

    • You can use the merged manifest view to preview the effect of merging manifests and find conflicting errors.

Basic manifest files that can be merged with each other, with the following priority levels (priority high to low):

    1. Manifest file Build variants
      If the variant has multiple source sets, its manifest priority is from high to low as follows:
      A. Build a Variant manifest file (e.g. Src/demodebug)
      B. Build type list (e.g. src/debug/)
      C, Product customization list (e.g. src/demo/)
      If you are using custom latitude, the manifest priority corresponds to the order in which each dimension is listed in the Flavordimensions attribute (high priority to low).
    2. The main manifest file for the application module
    3. Manifest files in the included libraries: if there are multiple libraries, the manifest priority matches the order of dependencies (the order in which the libraries appear in the Gradle dependencies block).

Important: The build configuration in the Build.gradle file replaces any corresponding attribute in the merged manifest file. The minsdkversion in the Build.gradle file will replace the matching attribute in the manifest element.

Merge conflict heuristic algorithm

Merge tool behavior:

    • Attributes in an element are never merged, using only the attributes in the highest-priority manifest.
    • attributes, and elements are combined using or, so if there is a conflict, the system will take "true" and always include the functionality or library required for a manifest.
    • Elements always use values from higher-priority manifests, except for the following:
      • If the low-priority list has a higher minsdkversion value, the overridelibrary merge rule is applied. (Minsdkversion use a larger value)
      • If the low-priority list has a lower targetsdkversion value, the merge tool will use the values from the high-priority list, but will also add any necessary system permissions. (Targetsdkversion use a larger value)
    • Never match elements between lists . Each element is treated as a unique element and added to the consolidated manifest.

Important: Manifest merging does not rely on default property values. Therefore, each attribute should be clearly defined as expected. (the default value for each property is recorded in manifest Reference:https://developer.android.com/guide/topics/manifest/manifest-intro)

Merge rule Tags

You can apply tags to the entire element or only to specific attributes in the element.
So the tags belong to the android tools namespace, so you must declare this namespace in the element now:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.myapp"    xmlns:tools="http://schemas.android.com/tools">
Node Tag:
    • Tools:node= "Merge"-The default behavior, merging all the attributes in this tag and all nested elements.
    • Tools:node= "Merge-only-attributes"-merges only the attributes in this tag and does not merge nested elements
    • Tools:node= "Remove"-removes this element from the merge manifest and removes the element from the low-priority list
    • Tools:node= "RemoveAll"-removes all elements that match this element type (within the same parent element)
    • Tools:node= "Replace"--completely replacing low priority elements
    • Tools:node= "Strict"-the configuration of the markup element in the low-priority list does not exactly match the high-priority list, triggering a build failure. (The default behavior adds extra attributes to the merge manifest)
Attribute Tags:
    • Tools:remove= "Attr1,attr2,..."--delete the specified attribute
    • Tools:replace= "Attr1,attr2,..."--Replacing the low priority list specifies that the property is a property in the current manifest
    • tools:strict= "ATTR1,ATTR2,..."-Triggers a manifest merge error when the specified attribute is not fully consistent with the current manifest in a low-priority list. is the default behavior for property merges.
    • Support for using multiple tags for the same element
Tag Selector:
    • Tools:selector= "Lib1,lib2,..."-Apply merge rule tags for a specific import library
    • tools:overridelibrary= "Lib1,lib2,..."--replaces the specified import library
      • By default, importing a library with a minsdkversion value higher than the main manifest file can make an error and cannot import the library.
      • With Overridelibrary, you can keep your app's low minsdkversion.
Implicit system permissions

Implicit permissions: Allows the app to continue accessing specific APIs without permission, provided the app's targetsdkversion is set to a value lower than the SDK version of the add limit.

Principle:

    • If the low-priority manifest file provides implicit permissions for a lower targetsdkversion value, and the high-priority manifests do not have the same implicit permissions, the merge tool adds system permissions to the consolidated manifest display.

The merge tool can be added to the list of permissions for the consolidated manifest:

low-priority list declaration permissions added to the consolidated manifest
Targetsdkversion is 3 or less Write_external_storage, Read_phone_state
Targetsdkversion is 15 or lower and uses read_contacts Read_call_log
Targetsdkversion is 15 or lower and uses writer_contacts Write_call_log

Specific Merge strategy:

    • Merge: Merges all non-conflicting attributes into the same tag, and then merges the child elements by their respective merge policies. Conflicting properties are merged using the merge rule tag.
    • Merge only children: Do not consolidate or merge attributes (only attributes provided by high-priority manifest files are retained)
    • Keep
Summarize

Checklist Merge conflict: Open the Androidmanifest.xml file in Android Studio, the merged Manifest tab at the bottom of the stand-alone editor.
Merge policy: Tag settings by merging rules.

The Android manifest files merge those things

Related Article

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.