GiovanniBattista opened a new issue, #201:
URL: https://github.com/apache/cordova-common/issues/201

   # Bug Report
   
   ## Problem
   I have created an internal cordova plugin at our company which adds the 
android:networkSecurityConfig attribute to the /manifest/application/ tag in 
AndroidManifest.xml via the following `<edit-config`:
   ```
   <edit-config file="AndroidManifest.xml" mode="merge" 
target="/manifest/application">
      <application 
android:networkSecurityConfig="@xml/uq_network_security_config" />
   </edit-config>
   ```
   
   This works flawlessly if the plugin is added the first time. But if the 
plugin is removed and then re-added again an error occurrs.
   
   ### What is expected to happen?
   The plugin should be added again without any issues.
   
   
   ### What does actually happen?
   If the plugin is re-added, the following error is produced:
   ```
   Failed to install 'uq-cordova-plugin-settings': TypeError: Cannot read 
properties of undefined (reading 'id')
       at registerConflict 
(D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:255:43)
       at 
D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:283:34
       at Array.forEach (<anonymous>)
       at PlatformMunger._is_conflicting 
(D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:259:21)
       at PlatformMunger.add_plugin_changes 
(D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:106:59)
       at D:\CordovaApp\node_modules\cordova-common\src\PluginManager.js:120:33
       at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5)
   Cannot read properties of undefined (reading 'id')
   ```
   
   
   ## Information
   The problem is that, upon removal, the `platforms/android/android.json` 
looks like the following:
   ```
   "AndroidManifest.xml": {
     "parents": {
       "/*": [
         {
           "xml": "<uses-permission 
android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />",
           "count": 1
         },
         {
           "xml": "<queries><intent><action 
android:name=\"android.media.action.IMAGE_CAPTURE\" /></intent><intent><action 
android:name=\"android.intent.action.GET_CONTENT\" /></intent><intent><action 
android:name=\"android.intent.action.PICK\" /></intent><intent><action 
android:name=\"com.android.camera.action.CROP\" /><data 
android:mimeType=\"image/*\" android:scheme=\"content\" /></intent></queries>",
           "count": 1
         },
         ...
       ],
       "application": [],
       "/manifest/application": []
     }
   }
   ```
   Notice the empty array for `/manifest/application`. 
   
   The code in `ConfigChanges.js` `registerConflict` accesses the first entry 
in the array, which does not exist in this case. Therefore, the above error is 
being thrown. 
   
![image](https://github.com/apache/cordova-common/assets/12544460/1a72aaca-c3f1-45e4-814f-4afbd8dc48bc)
   
   With a slight adjustment to the code the above error could be avoided, but 
it leads to another error ("There was a conflict trying to modify attributes 
with") which is a different issue, I guess.
   
![image](https://github.com/apache/cordova-common/assets/12544460/d6ca3d2f-0d15-4333-b7c9-36c98984e583)
   
   
   ### Command or Code
   Create a new cordova project, create a new plugin directory with the 
`<edit-config` lines from the beginning of the issue. 
   ```
   cordova create hello com.example.hello HelloWorld
   mkdir cordova-plugin-test
   # add plugin.xml and package.json to cordova-plugin-test
   cd hello
   cordova platform add [email protected]
   cordova plugin add ..\cordova-plugin-test
   cordova plugin remove cordova-plugin-test
   cordova plugin add ..\cordova-plugin-test
   # => produces the error
   ```
   
   A minimum viable plugin.xml looks like this:
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0";
           id="cordova-plugin-test" version="0.0.1">
       <name>Test</name>
       <description>Cordova Device Test</description>
       <license>Apache 2.0</license>
       <keywords>cordova,test</keywords>
   
       <platform name="android">
         <edit-config file="AndroidManifest.xml" mode="merge" 
target="/manifest/application">
               <application 
android:networkSecurityConfig="@xml/uq_network_security_config" />
           </edit-config>
       </platform>
   </plugin>
   ```
   The package.json looks like this:
   ```
   {
     "name": "cordova-plugin-test",
     "version": "1.0.0",
     "description": "",
     "main": "index.js",
     "scripts": {
       "test": "echo \"Error: no test specified\" && exit 1"
     },
     "author": "",
     "license": "ISC"
   }
   ```
   
   
   ### Environment, Platform, Device
   Environment: Windows 10 with PowerShell
   
   
   
   ### Version information
   Cordova-Cli: 12.0.0 ([email protected])
   Cordova Platform Android: 12.0.0
   Windows 10
   PowerShell 7
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to