Merge Mutiple Manifest File
 

Merge Mutiple Manifest File

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:

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:

 

High priority manifest:

 

Merged manifest result:

 

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:

 

High priority manifest:

 

Merged manifest result:

 

For more details go to link, https://developer.android.com/studio/build/manifest-merge.html#merge_rule_markers