Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Abandoned
-
2.1.1
-
None
Description
If <config-file> tries to add an element to a config file, and that config file has the same element but with extra attributes, the element is added anyway. I expect it to consider it already existing and skip adding it.
Example:
1. Add cordova-plugin-file plugin, which contains this line in plugin.xml:
<config-file target="AndroidManifest.xml" parent="/*"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </config-file>
2. Since WRITE_EXTERNAL_STORAGE is not required on Android API 19+ (Android 4.4+), I want to add android:maxSdkVersion="18" to the permission. So I add this to the app's config.xml
<edit-config file="AndroidManifest.xml" mode="overwrite" target="/manifest/uses-permission[@android:name='android.permission.WRITE_EXTERNAL_STORAGE']" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:maxSdkVersion="18" android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </edit-config>
3. Run cordova run android. It succeeds the first time and the permission is modified correctly. AndroidManifest.xml now contains this:
<uses-permission android:maxSdkVersion="18" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3. Run cordova run android again. The <config-file> from cordova-plugin-file is applied again. It searches for the exact element it wants to add and doesn't find it (because that element now has an extra attribute, android:maxSdkVersion), and so it adds it again. AndroidManifest.xml now contains this:
<uses-permission android:maxSdkVersion="18" android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This causes cordova run android to fail with:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:20:5-81 duplicated with element declared at AndroidManifest.xml:18:5-108
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.