Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-13474

Plugin with "<edit-config>" tag removes XML elements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • cordova-common
    • None
      • cordova v7.1.0
      • android platform v6.3.0

    Description

      I have two plugins which modify the `AndroidManifest.xml` file.
      The first plugin just adds an `<activity>` element.
      The second plugin also adds some `<activity>` elements AND modifies the `<application>` element by adding the XML attribute `android:largeHeap="true"` via "<edit-config>" tag.
      The first plugin works well. But the second plugin removes the `<activity>` element of the first plugin.

      I have created two dummy plugin repos to reproduce this issue:

      Repro steps:

      cordova create PluginTestApp
      cd PluginTestApp/
      cordova platform add android
      cordova plugin add https://github.com/eddyfrank/cordova-plugin-1
      

      Content of the `platforms/android/AndroidManifest.xml` after adding `cordova-plugin-1`:
      Looks good so far - the activity element `<activity android:name="com.example.plugin1.ActivityX" />` was added correctly.

      <?xml version='1.0' encoding='utf-8'?>
      <manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.plugintestapp" xmlns:android="http://schemas.android.com/apk/res/android">
          <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
          <uses-permission android:name="android.permission.INTERNET" />
          <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
              <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
                  <intent-filter android:label="@string/launcher_name">
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                  </intent-filter>
              </activity>
              <activity android:name="com.example.plugin1.ActivityX" />
          </application>
          <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
      </manifest>
      

      OK, let's add the second plugin:

      cordova plugin add https://github.com/eddyfrank/cordova-plugin-2
      

      Got following error:

      Installing "cordova-plugin-2" for android
      Failed to install 'cordova-plugin-2': Error: There was a conflict trying to modify attributes with <edit-config> in plugin cordova-plugin-2. The conflicting plugin, undefined, already modified the same attributes. The conflict must be resolved before cordova-plugin-2 can be added. You may use --force to add the plugin and overwrite the conflicting attributes.
          at PlatformMunger.add_plugin_changes (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/cordova-common/src/ConfigChanges/ConfigChanges.js:148:19)
          at /Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:123:29
          at _fulfilled (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:854:54)
          at self.promiseDispatch.done (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:883:30)
          at Promise.promise.promiseDispatch (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:816:13)
          at /Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:877:14
          at runSingle (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:137:13)
          at flush (/Users/eddy/work/projects/test-projects/cordova/PluginTestApp/platforms/android/cordova/node_modules/q/q.js:125:13)
          at _combinedTickCallback (internal/process/next_tick.js:67:7)
          at process._tickCallback (internal/process/next_tick.js:98:9)
      Error: There was a conflict trying to modify attributes with <edit-config> in plugin cordova-plugin-2. The conflicting plugin, undefined, already modified the same attributes. The conflict must be resolved before cordova-plugin-2 can be added. You may use --force to add the plugin and overwrite the conflicting attributes.
      

      => Issue 1:

      • Why does this error occur? There is no plugin in the project which has already modified attributes in the `<application>` element.
      • The error message does not name the plugin: `The conflicting plugin, undefined, already modified the same attributes.`

      Anyway, lets try to add `cordova-plugin-2` with `--force`:

      cordova plugin rm cordova-plugin-2
      cordova plugin add https://github.com/eddyfrank/cordova-plugin-2 --force
      
      Installing "cordova-plugin-2" for android
      --force is used. edit-config will overwrite conflicts if any. Conflicting plugins may not work as expected.
      Adding cordova-plugin-2 to package.json
      Saved plugin info for "cordova-plugin-2" to config.xml
      

      Content of the `platforms/android/AndroidManifest.xml` after force adding the `cordova-plugin-2`:

      <?xml version='1.0' encoding='utf-8'?>
      <manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.plugintestapp" xmlns:android="http://schemas.android.com/apk/res/android">
          <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
          <uses-permission android:name="android.permission.INTERNET" />
          <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:largeHeap="true" android:supportsRtl="true">
              <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
                  <intent-filter android:label="@string/launcher_name">
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                  </intent-filter>
              </activity>
              <activity android:name="com.example.plugin2.ActivityY" />
              <activity android:name="com.example.plugin2.ActivityZ" />
          </application>
          <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
      </manifest>
      

      => Issue 2 (the actual issue):

      The attribute `android:largeHeap="true"` was added correctly but the activity element `<activity android:name="com.example.plugin1.ActivityX" />` of the first plugin `cordova-plugin-1` was removed!
      Please note: Without the "<edit-config>" tag in the `cordova-plugin-2` everything works fine. So it seems the merging functionality of the "<edit-config>" tag is buggy.

      Tested with:

      • cordova v7.1.0
      • android platform v6.3.0

      Attachments

        Activity

          People

            Unassigned Unassigned
            ef23 Eddy Frank
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: