Windows Phone 10 build steps

Hi there,

I’m getting the following error when building for Windows 10 phone. Any idea what I can do about it? I’ve already updated VS 2015 to latest (update 3) and included the Cordova tools. I also added the following element to my config.xml.

<preference name="windows-target-version" value="10.0" />

Here are the errors I get when I run ‘ionic build windows’:

C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\Microsoft.Cpp.VCLibs120Universal.targets(103,5): warning MSB3842: Project “CordovaApp.Windows10” depends upon SDK “Microsoft Universal CRT Debug Runtime v10.0.14393.0” which supports apps targeting “UAP 10.0”. To verify whether “Microsoft Universal CRT Debug Runtime v10.0.14393.0” is compatible with “UAP 10.0.14393.0”, contact the SDK author or see http://go.microsoft.com/fwlink/?LinkID=309181. [myPath\App\platforms\windows\CordovaApp.Windows10.jsproj]

C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\Microsoft.Cpp.VCLibs120Universal.targets(103,5): error MSB3779: The processor architecture of the project being built “Any CPU” is not supported by the referenced SDK “Microsoft.UniversalCRT.Debug, Version=10.0.14393.0”. Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: “x86, x64, ARM, ARM64”. [myPath\App\platforms\windows\CordovaApp.Windows10.jsproj]

Regarding the latter of the two errors, I’ve already set the build platform in VS to read ‘Windows-ARM’ and checked the project configuration matches (both debug and release mode are set to Windows-ARM).

FYI, I’ve tried finding docs for the win 10 build process, but the questions on this site haven’t been answered and there are no links to resources that are explicitly Ionic 2 / win 10 phone. If I should be using Cordova-specific docs, then please let me know.

Thanks! :slight_smile:

1 Like

OK, so I worked through it for about 8 hours (I think a big part of the problem was expecting a single site would have all the information required (i.e. Ionic’s docs), but in the end it needed info from Ionic, Cordova and Microsoft. Anyway, here are my notes:

Debugging on windows mobile devices

Ensure you’ve run ‘ionic platform add windows’.
Open the windows 10 project from the platforms/windows folder (you can open the solution, but if you do, ensure the win 10 project is set as default startup).
Set cpu type to windows-ARM (for the Lumia 550).

Config.xml

Open config.xml (designer view) and add any API endpoints to the ‘Domain Access’ list in the ‘Common’ tab.
You can find out more about the config.xml here:
Cordova: Config.xml

Under the ‘windows’ tab, make sure Windows 10 is the target version.

Certificates

Win phone aps require a locally-stored certificate to access resources over SSL.

Download the cert from the server
(do it via browser, click on padlock or similar and save as DER type - which has .cer extension for some reason).
Save cert to project root e.g. ‘api-certificate.cer’

add the following to package.windows10…appxmanifest

<Extensions>
    <!--Certificates Extension-->
    <Extension Category="windows.certificates">
        <Certificates>
            <Certificate StoreName="Root" Content="api-certificate.cer" />        
        </Certificates>
    </Extension>
</Extensions>

If required, additional certs could be added via this method (I guess).

Ensure to include the .cer in the project, as it will need to be included in the built package.

Binaries

The debugging process might require a bunch of binaries that aren’t copied into the package by default.
For me, it wasn’t copying SqlLite, which needs to be copied to the debug folder and any chip-architecture-specific dependency folders such as ARM. You’ll get errrors which show which files are missing (I even had empty folders created for them).

Build

Build the app in VS (you can build with ‘ionic build windows’ but this has been failing for me since it tries to build the generated windows project without setting the cpu architecture first).
Go to projectfolder > platforms > windows and open the cordovaapp.sln.
Set the windows 10 project to be startup default and check that it’s set to windows-ARM.

Build solution.

Package app

MSDN: Packaging UWP Apps

Make sure the win 10 project’s appxmanifest file contains a content URI for the data API:

https://api.example.com (Rule: include and WinRT: all)

Copy the api-certificate.cer file into the platform > windows folder (or use the ./reload-platform windows powershell script).

Go to project > store > create app package.
Select ‘No’ for local package creation and follow wizard (prob. only need to choose the right architecture).
The .cer file for API will be included in the package.

The package will be created in the AppPackages folder with a [projectName].[verion] folder name.

Deployment

If it’s running on a USB-attached device, then it’s probably deployable to the app store.

Here’s a rough assemblage of useful resources:

TACO-VS: Packaging Windows Apps
MSDN: Side-loading or Developer Mode?
Technet: Side-load apps in Windows 10

Configure device to accept side-loaded apps

MSDN: Enable Side-Loading

To use developer features

On your device that you want to enable, go to Settings. Choose Update & security, then choose For developers.
Choose the level of access that you need - to develop UWP apps, choose Developer Mode, otherwise choose ‘sideload apps’.
Read the disclaimer for the setting you chose, then click Yes to accept the change.

Optional: Deploy using winappdeploycmd.exe

(MSDN: Using WinAppDeployCmd.exe for deploying UW apps](https://msdn.microsoft.com/windows/uwp/packaging/install-universal-windows-apps-with-the-winappdeploycmd-tool)

Check available devices locally
C:“Program Files (x86)”“Windows Kits”\10\bin\x86\winappdeploycmd devices

Note: this process (winappdeploycmd) probably isn’t much use, since we’ll either give files to unmanaged-device customers or
let them download it from app store, but it may be useful in lieu of visual studio.

Copy .cer and .appxbundle to phone and install

Connect the phone to PC via USB and copy two files from the newly-built folder on to the phone (e.g. the downloads folder):

Example file names

CordovaApp.Windows10_0.0.2.0_arm.cer
CordovaApp.Windows10_0.0.2.0_arm.appxbundle

Open File Explorer on the phone and click the .cer (certificate) first. Let it install.
Installing the certificate allows a sideload-enabled system to install signed appxbundles containing the app.
Next, click on the appxbundle file and let that install too (wait for 30 secs as it is still installing in background).
NOTE: Do not try to open the app unless it has appeared in the ‘recent items’ list,
otherwise you’ll get some silent errors due to missing assets and the screen will go blank or just return to device home menu.

Once it’s appeared in the apps menu, you can load normally.

Validation

With a developer license, apps can be validated before submittal into the app store.

MSDN: Validate Package

MSDN: Using the Windows App Certification Kit

4 Likes

Good stuff! I would have helped you out, but I just saw this post this morning. Looks like you’ve solved your problems already.

1 Like

Yeah, thanks @mtycholaz, it was horribly confusing, but came together in the end :slight_smile:

Is the steps same for widows 10 UWP?
I am curious Ionic 2 only support win10 UWP? How about Windows 8.1 for PC and phone?
Can we build one for all these?

I just spent about five hours wading though this quagmire as well. Following the steps above, I could get the project to build in VS2015 but not to run on the device (Nokia Lumia 640 running Windows 10) as I kept getting various remote debugger errors.

In the end I managed to get it working from the command line instead. So, after

ionic platform add windows

I tried

cordova run windows --device -- --arch=ARM --phone

This builds it, then gives a warning

Cannot launch app with current version of Windows 10 SDK tools. You will have to launch the app after installation is completed

then an error

Unexpected error from installation: C:\Program Files (x86)\Windows Kits\10\bin\x86\WinAppDeployCmd.exe: Command failed with exit code 2147943860 You may have previously installed the app with an earlier version of cordova-windows. Ensure the app is uninstalled from the phone and then try to run again."

then after 10 - 20 seconds the app icon appears in the list and you can run the app on the device. Each time you want to run it again you have to manually uninstall the app from the phone first otherwise it fails next time round.

My Cordova version is 6.4.0

So far I’ve not been able to figure out a way to attach to the process for live debugging etc but you can actually test the app out on a real device. I’m developing on my Mac and then just pulling the code in from git to Windows so hopefully it won’t be too much of an issue for me but could be a struggle for Windows only folks.

My project has the default Cordova plugins that Ionic installs (RC1) and the cordova-sqlite-storage plugin providing the data store for PouchDB.

There’s a lot more latency on the Windows phone compared to Android (4.4.4+) and iOS (9 and 10) but it does work ok. I’d say verging on the unusable but probably tolerable if I can add some activity indicators in to the let the user know that there is actually something happening while they’re waiting for the next view on the navigation stack.

I’ve got API integration next so hopefully @Astravagrant’s certificate steps will help me there but thought I’d post this for any other intrepid souls venturing down the Windows path.

i try " cordova run windows --device – --arch=ARM --phone " but error show me "Error: cannot read property ’ __ip’ of undefined ‘’.

After I posted that I did some code changes and then tried to follow the same steps and I couldn’t get it to work again either, I think with a similar error message if I remember rightly.

In the end I gave up on Windows as it was just taking too much time trying to get it to work so I’m not sure how to fix this I’m afraid

1 Like

Thanks for this. The only step I’m struggling with is the certificates part.
My app attempts to upload a video file to Amazon S3 and I think it’s failing because of a non existent certificate on the device, like you’ve outlined.

Any idea how to download an Amazon S3 SSL certificate? I can’t see a way.

Here’s my StackOverflow question for reference, if you’ve got a sec?

Thanks again

Hello,

I have EXACTLY the same errors as yours.
I went through your solution and had some questions.

Where to Set the CPU type? Which file in the project??

How to ensure that the Win10 project is set as default startup? do we have to write certain code or choose something somewhere in the project?

Which Server should I download it from? can you give me a link to download it from somewhere?
Also, is the project root outside the www folder or inside it? I am guessing outside the www folder.

HOW to include the .cer project and where to include it? Do we have to write some code? And WHEN do we have to include it? At built time?

Can you elaborate what exactly is a Binary file?
I too have SQLite plugin in my app. Can you tell me where did you download the binary from?
download Link for the same probably? And for which other plugins do you think we would need binaries for?

Thanks in advance. Hope you help me out :slight_smile:

1 Like

Hi ng22792,

The build process for windows generates a visual studio (VS) project in the build folder of your app. If you don’t have VS,t hen download the community version (free and very powerful). If you haven’t used it before, you’ll need to spend some time with it, as it has a LOT of features. But you should be able to finish building your app before too long.

When you load this, you can set the build for ‘cpu type’ setting. It’s a drop down menu in the IDE itself (debug menu, I think).

Again, this project should be set as startup (I can’t remember how many projects in the VS solution, so maybe there is only one).

The .cer file needs to be in the same folder as the project (i.e. project root).

The binary file might not be an issue for you and is complicated, so I won’t explani more (I can’t really remember anyway, it was a long time ago now :slight_smile: Try to see if it works, but if not then find the missing files in the project folder somewhere (/platforms/, maybe?) and manually copy them to the relevant folder (copy them to any folder you think might work if you are not sure! then remove them one by one :wink:

I hope that helps.

1 Like

Dear Astravagrant,

I had installed VS2015 and got some clarity after I spoke to some native Windows developers about the minor doubts, other than that my errors got sorted by changing the error description to ‘detailed’, and then getting to know the real problems. the problem was due to some .d.ts files in my angular js ui router libraries. I got things straight by Deleting the d.ts files in my lib/angular-ui-router/api and removing and adding the windows build again. Changing the v141 to v140 in my sqlite plugin folder was also effective. Thanks a lot for replying. Glad the Community helps :slight_smile: responds back ! Cheers.

Hey, i don’t understand the following part.

Download the cert from the server (do it via browser, click on padlock or similar and save as DER type - which has .cer extension for some reason). Save cert to project root e.g. 'api-certificate.cer'

what and where should i download the cert from which server? :see_no_evil:

thanks :hugs: