The intent-filter element never changes and is always added to the parent node of the same merged list.
Important: After the configuration file is merged, use any settings in the build. gradle file to overwrite the final configuration. For more details, see Configure Gradle Builds.
Merge conflict tags and selectors
------------------------------------------------------------------
The configuration tag and Selector overwrite the default rules by creating a conflict resolution. For example, use a conflicting identifier to merge the minSdkVersion of a library list with a higher priority list, or merge the Activity with the same list but with different android: theme values.
Merge conflicting identifiers
A Merge conflict identifier is a specified Element in the Android tool space. It defines a specified merge Conflict scheme. Create a conflict identifier to avoid merge conflict errors that are not resolved using the default merge rules. The following table lists the supported merge conflict identifiers:
Merge
Merge attributes when there are no merging rule conflicts. The default merge action.
Replace
Use a high-priority list to replace attributes in a low-priority list;
Strict
Merge-only
Allows merging of low-priority attributes;
Remove
Delete the low-level elements specified in the merged list;
Remove-All
Delete all low-priority elements of the same node type in the merged list;
By default, the merge process of the list applies the merge conflict identifier at the node level. By default, all declared configuration attributes are strict merge policies.
To set a merging conflict identifier, first declare the namespace in the AndroidManifest. xml file. Then, enter a specified merge conflict action for the merged conflict identifier in the list. In this example, the replace identifier is inserted to set a replace action to solve the conflict between the elements in the android: icon and android: lable list.
...
Tag attributes
The conflicting identifiers use the tools: node and tools: attr attributes to perform conflicting actions at the XML node or attribute level.
Tools: the attr identifier only uses restrict, remove, and replace. Multiple tools: the value of the attr identifier can be applied to a specified element. For example, you can use tools: replace = "icon, lable, theme" to extract lower-priority icons, lable, and theme attributes.
Inject build values into the inventory file
-----------------------------------------------------------------
Configuration File merging can also use a list placeholder to inject attribute values to the configuration property from the build. gradle file.
The configuration placeholder uses this syntax $ {name} to set the attribute value. The name is the build. gradle attribute injected, And the build. gradle file uses the manifestPlaceholders attribute to define the placeholder value.
Note: unresolved placeholder names in the app may cause building failure. Warnings are generated for unresolved placeholders in the library and must be resolved when the library is imported into an app.
In this example, the placeholder $ {applcationId} is used to map the applicationID property value of build. gradle to the android: name property value.
Note: Android Studio provides a default $ {applicationID} placeholder for the build. gradle applicationId value, which is not displayed in the build file. When creating an AAR (Android ARchive) package for the library module, you do not need to provide an automatic @ {applicationID} placeholder in the configuration merging settings. Instead, use a different placeholder, such as @ {libApplicationID}, and provide a value for the archive library if you want to include the appliction Id.
List entity:
Build file:android { compileSdkVersion 22 buildToolsVersion "22.0.1" productFlavors { flavor1 { applicationId = "com.mycompany.myapplication.productFlavor1" } }
Merge list values:
The placeholder configuration file and the manifestPlaceholders attribute of the build file can be used to inject other configuration file values. For applicationId dependency attributes, the manifestPlaceholders attributes are explicitly declared in the build. gradle file. This example shows how to inject the activityLabel value into the placeholder list.Gradle build file:
android { defaultConfig { manifestPlaceholders = [ activityLabel:"defaultName"] } productFlavors { free { } pro { manifestPlaceholders = [ activityLabel:"proName" ] } }
Build file:android { defaultConfig { manifestPlaceholders = [ activityLabel:"defaultName"] } productFlavors { free { } pro { manifestPlaceholders = [ activityLabel:"proName" ] } }
Placeholders in the list file:
Note:Placeholder values support partial value injection, such as android: authority = "com. acme. $ {localApplicationId}. foo ".
Combine and list files using Product Flavor
-----------------------------------------------------------------
When the GroupbleProductFlavor attribute is used, the merging priority of any configuration files in the Product flavor group depends on the order in the build files. The configuration file merging process is based on the build variant build configuration, creating a separate merge configuration file for the product flavor group.
For example, if a build varian from their respective product flavor group ABI, Density, API and Prod refer to product flavors x86, mdpi, 21, and paid, in build. the gradle file is arranged in this order, and then the configuration file is sorted by product flavors in the order of priority in the build file.
To illustrate this example, the following identifier shows the product flavor list in each product flavor group. The combination of product flavors and group defines build variant.
Product Flavor Group |
Product Flavor |
ABI |
X86 |
Density |
Mdpi |
API |
22 |
Prod |
Paid |
Order of list merging:
Prod-paid AndroidManifest. xml (low priority) is merged into AndroidManifest. xml API-22
API-22 AndroidManifest. xml merged into density-mpi AndroidManifest. xml
Density-mpi AndroidManifest. xml merge to ABI-x86 AndroidManifest. xml (high priority)
Implicit permission
-----------------------------------------------------------------
Import an Android running library that supports implicit permission granting. This permission may be automatically added to the merged list. For example, if an application whose targetSdkVersion is 16 is imported into a database whose targetSdkVersion is 2, Andorid Studio adds the WRITE_EXTERNAL_STORAGE permission to ensure compatibility across SDK versions.
Note: More current Android versions replace implicit permission declarations.
Importing this library version |
Declares this permission in the manifest |
TargetSdkVersion <2 |
WRITE_EXTERNAL_STORAGE |
TargetSdkVersion <4 |
WRITE_EXTERNAL_STORAGE, READ_PHONE_STATE |
Declared WRITE_EXTERNAL_STORAGE |
READ_EXTERNAL_STORAGE |
TargetSdkVersion <16 and using the READ_CONTACTS permission |
READ_CALL_LOG |
TargetSdkVersion <16 and using WRITE_CONTACTS permission |
WRITE_CALL_LOG |
Handle configuration merging and building errors
------------------------------------------------------------------
During the build process, the configuration merging process is in the mainfest-merge- The -report.txt file records each merged transaction. Build variants of each module generates different log files.
When a configuration merge build error occurs, the build process records the error message describing the merge conflict in the log file. For example, a build error android: screenOrientation merge conflict occurs between the following lists.
High-priority list declaration:
Low-priority list declaration:
Error Log:/project/app/src/main/AndroidManifest.xml:3:9 Error: Attribute activity@screenOrientation value=(portrait) from AndroidManifest.xml:3:9 is also present at flavorlib:lib1:unspecified:3:18 value=(landscape) Suggestion: add 'tools:replace="icon"' to element at AndroidManifest.xml:1:5 to override