ionic cordova fail to build app with duplicate elements (CAMERA) at AndroidManifest.xml

Hi Every one!

I would like to share a solution for below error after I have suffered with it for couple of days.




CAUSE OF THE ERROR
This is error occurs when there are two or more same xml elements in the AndroidManifest.xml file. as shown on the figure below


This duplication occurs if you add two plugins that use camera (i.e barcodescanner and camera plugin ). Each of the two plugins has a file called plugin.xml found in ./plugins/plugin_name/plugin.xml. The elements (e.g uses-permission android:name="android.permission.CAMERA") are also added to the android.json file found in ./platform/android/android.json NOW, when build the app, The merger tool combines all the manifest files (plugins.xml) into one file (AndroidManifest.xml file) by merging them sequentially based on each manifest file's priority. (Ref: Merge multiple manifest files)
If the merging tool found the element from one manifest file (plugin.xml file) which is also found in another manifest file and differ in attribute, the tool will add the element to the AndroidManifest.xml which in turn causes the duplication of the element though they differ in number of attributes.

SOLUTION
The only solution that I figured is to remove the duplicate elements from from the manifest.xml file of one plugin among the two BUT REMEMBER: The elements from each plugin added, are also added to the android.json file. Therefore, it is the best to remove all duplicate elements from every manifest.xml file and leave this job for android.json to add the element to AndroidManifest.xml during merging by merging tool

Maoni

Machapisho maarufu kutoka blogu hii