Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Build command needs to be run twice to apply config.xml changes to appxmanifest #336

Closed
2 of 3 tasks
dominic-simplan opened this issue May 16, 2019 · 7 comments
Closed
2 of 3 tasks
Assignees
Labels

Comments

@dominic-simplan
Copy link

Bug Report

Problem

What is expected to happen?

Changes to the config.xml should be reflected in the AppxManifest.xml / package.*.appxmanifest file after running the build command.

What does actually happen?

Adding for example this configuration to the main config.xml:

<platform name="windows">
        <config-file parent="/Package/Capabilities" target="package.appxmanifest">
            <Capability Name="allJoyn" />
        </config-file>
    </platform>

And then building the application with cordova build windows -- --archs="x64" will:

  • Update the platforms\windows\config.xml correctly
  • Add the according element to the platforms\windows\windows.json file
  • Will not update the package.*.appxmanifest files

Running the cordova build windows -- --archs="x64" command a second time,

  • Will finally update the package.*.appxmanifest file

The build command needs to be run two times before the value is actually applied to the appxmanifest file.

Information

Environment, Platform, Device

Windows 10

Version information

Cordova 8.1.2
Cordova-windows 6.0.1 and 7.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@janpio
Copy link
Member

janpio commented Jul 4, 2019

Ugh, that sounds strange. Will try to reproduce.

@janpio janpio self-assigned this Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 5, 2019

Hm, I think I can not reproduce this:

I created the project this way:

E:\Projects\throwaway                                                                                                             
λ cordova create cordovaWindows336                                                                                                
Creating a new cordova project.                                                                                                   
                                                                                                                                  
E:\Projects\throwaway                                                                                                             
λ cd cordovaWindows336\                                                                                                           
                                                                                                                                  
E:\Projects\throwaway\cordovaWindows336  (helloworld@1.0.0)                                                                       
λ cordova platform add windows                                                                                                    
Using cordova-fetch for cordova-windows@^7.0.0                                                                                    
Adding windows project...                                                                                                         
Creating Cordova Windows Project:                                                                                                 
        Path: platforms\windows                                                                                                   
        Namespace: io.cordova.hellocordova                                                                                        
        Name: HelloCordova                                                                                                        
cp: no such file or directory: E:\Projects\throwaway\cordovaWindows336\node_modules\cordova-windows\node_modules\winjs\js\base.js 
                                                                                                                                  
cp: no such file or directory: E:\Projects\throwaway\cordovaWindows336\node_modules\cordova-windows\node_modules\winjs\js\base.js 
                                                                                                                                  
Windows project created with cordova-windows@7.0.0                                                                                
Plugin 'cordova-plugin-whitelist' found in config.xml... Migrating it to package.json                                             
Discovered saved plugin "cordova-plugin-whitelist". Adding it to the project                                                      
Installing "cordova-plugin-whitelist" for windows                                                                                 
Adding cordova-plugin-whitelist to package.json                                                                                   

Then I built once and commited everything to git:

E:\Projects\throwaway\cordovaWindows336 (master -> origin) (helloworld@1.0.0)                                                     
λ cordova build windows                                                                                                           
ENV var MSBUILDDIR is set C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin                          
Building project: E:\Projects\throwaway\cordovaWindows336\platforms\windows\CordovaApp.Windows10.jsproj                           
        Configuration : debug                                                                                                     
        Platform      : anycpu                                                                                                    
        Buildflags    : /p:AppxBundle=Never                                                                                       
        MSBuildTools  : C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin                            
buildProject spawn: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild [                      
  'E:\\Projects\\throwaway\\cordovaWindows336\\platforms\\windows\\CordovaApp.Windows10.jsproj',                                  
  '/clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal',                                                                       
  '/nologo',                                                                                                                      
  '/p:Configuration=debug',                                                                                                       
  '/p:Platform=anycpu',                                                                                                           
  '/p:AppxBundle=Never'                                                                                                           
] { stdio: 'inherit' }                                                                                                            
  prebuild.js: Patching platform `10`                                                                                             
  - Injected `base.js` reference to `/www/index.html`                                                                             
  - Removing /( *)(<script\s+(?:type="text\/javascript"\s+)?src="\/\/Microsoft.WinJS.2.0\/js\/base.js">\s*<\/script>)(\s*)/ from /
  tml                                                                                                                             
  - Removing /( *)(<script\s+(?:type="text\/javascript"\s+)?src="\/\/Microsoft.Phone.WinJS.2.1\/js\/base.js">\s*<\/script>)(\s*)/ 
  ndex.html                                                                                                                       
  CordovaApp.Windows10 -> E:\Projects\throwaway\cordovaWindows336\platforms\windows\AppPackages\CordovaApp.Windows10_1.0.0.0_anycp
  t\CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx                                                                                                                                                                                                               

Then I added the changes to config.xml you posted above and built again. This lead to the following git diff:

diff --git a/config.xml b/config.xml
index 7434b5e..faddf6e 100644
--- a/config.xml
+++ b/config.xml
@@ -23,4 +23,11 @@
         <allow-intent href="itms:*" />
         <allow-intent href="itms-apps:*" />
     </platform>
+
+    <platform name="windows">
+        <config-file parent="/Package/Capabilities" target="package.appxmanifest">
+            <Capability Name="allJoyn" />
+        </config-file>
+    </platform>
+    
 </widget>
diff --git a/platforms/windows/AppPackages/CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test/CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx b/platforms/windows/AppPackages/CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test/CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx
index 583aea4..d0bcdbc 100644
Binary files a/platforms/windows/AppPackages/CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test/CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx and b/platforms/windows/AppPackages/CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test/CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx differ
diff --git a/platforms/windows/build/windows/debug/anycpu/win10/AppxManifest.xml b/platforms/windows/build/windows/debug/anycpu/win10/AppxManifest.xml
index 36e605f..dc972a7 100644
--- a/platforms/windows/build/windows/debug/anycpu/win10/AppxManifest.xml
+++ b/platforms/windows/build/windows/debug/anycpu/win10/AppxManifest.xml
@@ -39,6 +39,7 @@
   </Applications>
   <Capabilities>
     <Capability Name="internetClient" />
+    <Capability Name="allJoyn" />
   </Capabilities>
   <build:Metadata>
     <build:Item Name="SharedGUID" Value="9ebdb27f-d75b-4d8c-b53f-7be4a1fe89f9" />
diff --git a/platforms/windows/config.xml b/platforms/windows/config.xml
index e87390b..e32ba6a 100644
--- a/platforms/windows/config.xml
+++ b/platforms/windows/config.xml
@@ -15,4 +15,7 @@
     <allow-intent href="sms:*" />
     <allow-intent href="mailto:*" />
     <allow-intent href="geo:*" />
+    <config-file parent="/Package/Capabilities" target="package.appxmanifest">
+        <Capability Name="allJoyn" />
+    </config-file>
 </widget>
diff --git a/platforms/windows/package.phone.appxmanifest b/platforms/windows/package.phone.appxmanifest
index f63fb9f..42ccab2 100644
--- a/platforms/windows/package.phone.appxmanifest
+++ b/platforms/windows/package.phone.appxmanifest
@@ -35,5 +35,6 @@
     </Applications>
     <Capabilities>
         <Capability Name="internetClientServer" />
+        <Capability Name="allJoyn" />
     </Capabilities>
 </Package>
diff --git a/platforms/windows/package.windows.appxmanifest b/platforms/windows/package.windows.appxmanifest
index f331373..3646983 100644
--- a/platforms/windows/package.windows.appxmanifest
+++ b/platforms/windows/package.windows.appxmanifest
@@ -35,5 +35,6 @@
     </Applications>
     <Capabilities>
         <Capability Name="internetClient" />
+        <Capability Name="allJoyn" />
     </Capabilities>
 </Package>
diff --git a/platforms/windows/package.windows10.appxmanifest b/platforms/windows/package.windows10.appxmanifest
index 3bfe9ba..c265ee8 100644
--- a/platforms/windows/package.windows10.appxmanifest
+++ b/platforms/windows/package.windows10.appxmanifest
@@ -32,5 +32,6 @@
     </Applications>
     <Capabilities>
         <Capability Name="internetClient" />
+        <Capability Name="allJoyn" />
     </Capabilities>
 </Package>
diff --git a/platforms/windows/windows.json b/platforms/windows/windows.json
index 8bd1274..c5a6807 100644
--- a/platforms/windows/windows.json
+++ b/platforms/windows/windows.json
@@ -4,7 +4,41 @@
     "uninstalled": []
   },
   "config_munge": {
-    "files": {}
+    "files": {
+      "package.phone.appxmanifest": {
+        "parents": {
+          "/Package/Capabilities": [
+            {
+              "xml": "<Capability Name=\"allJoyn\" />",
+              "count": 1,
+              "id": "config.xml"
+            }
+          ]
+        }
+      },
+      "package.windows.appxmanifest": {
+        "parents": {
+          "/Package/Capabilities": [
+            {
+              "xml": "<Capability Name=\"allJoyn\" />",
+              "count": 1,
+              "id": "config.xml"
+            }
+          ]
+        }
+      },
+      "package.windows10.appxmanifest": {
+        "parents": {
+          "/Package/Capabilities": [
+            {
+              "xml": "<Capability Name=\"allJoyn\" />",
+              "count": 1,
+              "id": "config.xml"
+            }
+          ]
+        }
+      }
+    }
   },
   "installed_plugins": {
     "cordova-plugin-whitelist": {

That looks correct to me. Am I missing something?

Note that I am using Cordova CLI 9.0.0 (cordova-lib@9.0.1) - maybe that makes a difference?

@janpio
Copy link
Member

janpio commented Jul 11, 2019

Ping @dominic-simplan

@dominic-simplan
Copy link
Author

@janpio thank you for taking the time to investige. I can confirm your behaviour with an empty project, but I still get the described issue within my project, even with cordova 9.0.0.

I've setup a new project in order to find out what's causing this issue (https://github.com/dominic-simplan/cordova-windows-config).
While trying to reproduce the issue, I came across a strange behaviour which I don't understand and which might be related.

After running cordova prepare in the linked project, windows.json contains the following (because of the camera plugin):

"package.windows10.appxmanifest": {
  "parents": {
    "/Package/Capabilities": [{
        "xml": "<DeviceCapability Name=\"webcam\" />",
        "count": 1
      }
    ]
  }
}

Now I add this to the config.xml and build the project:

<platform name="windows">
	<config-file parent="/Package/Capabilities" target="package.appxmanifest">
		<Capability Name="allJoyn" />
	</config-file>
</platform>

The windows.json now contains

"package.windows10.appxmanifest": {
  "parents": {
    "/Package/Capabilities": [{
        "xml": "<Capability Name=\"allJoyn\" />",
        "count": 1,
        "id": "config.xml"
      }
    ]
  }
}

Why is the webcam capability gone? <config-file> should append the tag, shouldn't it? Even if I remove the <config-file> from the config.xml again, the according object in the windows.json is now empty:

"package.windows10.appxmanifest": {
  "parents": {
    "/Package/Capabilities": []
  }
}

Before I do any further investigation, I need to understand if this behaviour is correct or not.

@janpio
Copy link
Member

janpio commented Jul 12, 2019

Interesting observation! Possible the "merging" of multiple config file changes is broken or behaving undefined. (Unfortunately I am not sure what should happen here - but sure doesn't seem good... I would have expected it to contain both, right?) (Next thing to investigate could be to just install 2 plugins that both write into the same file/path/xpath and see if these also overwrite).

@janpio
Copy link
Member

janpio commented Jul 12, 2019

@knight9999 Might this be another case of apache/cordova#95?

@timbru31
Copy link
Member

timbru31 commented Jan 9, 2023

We are archiving this repository following Apache Cordova's Deprecation Policy. We will not continue to work on this repository. Therefore all issues and pull requests are being closed. Thanks for your contribution.

@timbru31 timbru31 closed this as completed Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants