Our APK file can contain just one AndroidManifest.xml
file, but our Android Studio project may contain several—provided by the main source set, build variants, and imported libraries. So when building our app, the Gradle build merges all manifest files into a single manifest file that’s packaged into our APK.
Merge Priority :-
Library Manifest file -> Main Manifest file -> Build Variant Manifest File.
(From Lowest Priority to High Priority Manifest files)
There is conflict occurs in a single app while merging, So, how to solve it?
There are many merge rule marker and their method i.e. checks Merger Tools when merging manifest files.
All markers belong to the Android tools
namespace, so we must first declare this namespace in the <manifest>
element as shown here:
1 2 3 |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" xmlns:tools="http://schemas.android.com/tools"> |
I am talking only replace attribute of the marker.
Node Marker:-
tools:node="replace"
Replace the lower-priority element completely. That is, if there is a matching element in the lower-priority manifest, ignore it and use this element exactly as it appears in this manifest.
Example.
Low priority manifest:
1 2 3 4 5 6 |
<activity-alias android:name=”com.example.alias”> <meta-data android:name=”cow” android:value=”@string/moo”/> <meta-data android:name=”duck” android:value=”@string/quack”/> </activity-alias> |
High priority manifest:
1 2 3 4 5 |
<activity-alias android:name=”com.example.alias” tools:node=”replace”> <meta-data android:name=”fox” android:value=”@string/dingeringeding”/> </activity-alias> |
Merged manifest result:
1 2 3 4 |
<activity-alias android:name=”com.example.alias”> <meta-data android:name=”fox” android:value=”@string/dingeringeding”/> </activity-alias> |
Attribute Marker :-
If we want to apply the marker only attributes of manifest tag, then we use attribute marker.
Example:
tools:replace="attr, ..."
Replace the specified attributes in the lower-priority manifest with those from this manifest. In other words, always keep the higher-priority manifest’s values.
Low priority manifest:
1 2 3 4 |
<activity android:name=”com.example.ActivityOne” android:theme=”@oldtheme” android:exported=”false” android:windowSoftInputMode=”stateUnchanged”> |
High priority manifest:
1 2 3 4 5 |
<activity android:name=”com.example.ActivityOne” android:theme=”@newtheme” android:exported=”true” android:screenOrientation=”portrait” tools:replace=”android:theme,android:exported”> |
Merged manifest result:
1 2 3 4 5 |
<activity android:name=”com.example.ActivityOne” android:theme=”@newtheme” android:exported=”true” android:screenOrientation=”portrait” android:windowSoftInputMode=”stateUnchanged”> |
For more details go to link, https://developer.android.com/studio/build/manifest-merge.html#merge_rule_markers