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

<edit-config> in config.xml removes some XML elements added by plugins

VotersWatch issueWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Abandoned
    • 2.1.0
    • None
    • cordova-common
    • cordova-android 6.3.0

    Description

      Adding <edit-config> to config.xml is removing some XML elements added by plugins. For example, cordova-plugin-file-opener2 adds a <provider> element to AndroidManifest.xml. If I add an <edit-config> to config.xml that modifies AndroidManifest.xml, the <provider> element is removed on cordova (prepare|build|run) android

      To reproduce, create a cordova project with the following two files:

      package.json

      {
        "name": "com.example.test",
        "displayName": "Test",
        "version": "1.0.0",
        "dependencies": {
          "cordova-android": "6.3.0",
          "cordova-plugin-file-opener2": "2.0.19"
        },
        "cordova": {
          "platforms": [
            "android"
          ],
          "plugins": {
            "cordova-plugin-file-opener2": {}
          }
        }
      }
      

      config.xml

      <?xml version='1.0' encoding='utf-8'?>
      <widget id="com.example.test" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
          <name>Test</name>
          <content src="index.html" />
          <platform name="android">
              <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
                  <application android:allowBackup="false" />
              </edit-config>
          </platform>
          <engine name="android" spec="6.3.0" />
          <plugin name="cordova-plugin-file-opener2" spec="2.0.19" />
      </widget>
      
      

      Then run:

      $ npm install && cordova platform add android@6.3.0 --nosave
      [output omitted]
      $ cat ./platforms/android/AndroidManifest.xml

      <?xml version='1.0' encoding='utf-8'?>
      <manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.test" 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:allowBackup="false" 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>
              <provider android:authorities="${applicationId}.opener.provider" android:exported="false" android:grantUriPermissions="true" android:name="io.github.pwlin.cordova.plugins.fileopener2.FileProvider">
                  <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/opener_paths" />
              </provider>
          </application>
          <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
          <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      </manifest>
      

      $ cordova run android
      Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes
      [rest of output omitted]
      $ cat ./platforms/android/AndroidManifest.xml

      <?xml version='1.0' encoding='utf-8'?>
      <manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.example.test" 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:allowBackup="false" 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>
          </application>
          <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
          <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      </manifest>
      

      Note the missing <provider> element after running cordova run android

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            imgx64 Ibrahim M. Ghazal
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment