Part 8: Testing on WP8

We’ll take a short break from our compass application and I’ll describe my experience deploying an application for Windows Phone 8 on My Lumia 920 device.

If you want to compile Windows Phone 8 applications with PhoneGap/Cordova, make sure you have the following:

1. A windows machine (I used Windows 8.1)
2. The Windows Phone 8 SDK. My suggestion is to install the free Visual Studio 2012 for Windows Phone 8

Installing Cordova/PhoneGap on Windows:

The first thing I tried was to have the same CLI setup as I have on Linux and OS/X and for that I went through
1. Download the MSI installer for nodejs from http://nodejs.org/download/
2. npm did not run from the command line on Windows. It seems that the path settings that the setup made were wrong (showed C:UsersUSERAppDataRoamingnpm) so I changed it to c:Program Filesnodejs which is where node.exe was installed
3. npm install -g cordova

Although the last step above succeeded, I couldn’t get cordova to run from the command line. Tried setting the path to where the cordova module was installed and a bunch of other stuff but to no avail. Eventually I decided to let it go (for now) and compile a cordova project from Visual Studio Express 2012 for Windows Phone 8.

*Edit:* Don’t know what it was that fixed it, but at a certain point I tried issuing cordova from the command prompt and it worked. Perhaps I forgot to relaunch the windows command prompt after changing the path.

Note: (Sept 2014) – mkdir C:UsersUSERAppDataRoamingnpm since it isn’t created when node.js is installed

The bottom line is that everything works after the PATH is:

PATH=C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32
WindowsPowerShellv1.0;C:Program Filesnodejs;C:UsersUSERAppDataRoaming
npm

Make sure to read the next part about running from Visual Studio as it contains some important points and then I’ll continue with the standard method of using the Cordova CLI from windows prompt in the same manner as with Linux and OS/X


To build a cordova project from Visual Studio 2012, I followed the instructions on how to create a Cordova project template on Windows 8 with Visual Studio Express 2012 which are given here:

http://cordova.apache.org/docs/en/3.1.0/guide_platforms_wp8_index.md.html

Follow the above and You’ll be able to compile and deploy your application to your Windows Phone 8 device (I downloaded the latest copy of cordova instead of the phonegap copy they suggested, though it probably makes no difference).

Things you might run in to:

Upon trying to deploy the Cordova sample application to my Lumia 920 from Visual Studio, I got the following error:

Failed to connect to device as it is pin locked.

What the above means is that you have to have the phone open and be able to view the phone desktop in order that Visual Studio will be able to upload the compiled app to your device. For me all this meant was sliding the welcome screen.

I tried deploying again, and this time got:

Failed to connect to device as it is developer locked. For details on developer unlock, visit http://go.microsoft.com/fwlink/?LinkId=195284.

Naturally, I followed. and was redirected to:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769508(v=vs.105).aspx

Where they explain how to unlock your phone so you can start uploading Windows Phone 8 applications that you develop. Followed the simple registration steps and after that had no problem uploading the cordova app to Lumia 920.


Back to using the CLI from windows.

So after realizing cordova can now be run from the command line I invoked:

cordova create compass com.example.compass compass

which worked fine, followed by

cordova platform add wp8

which resulted in:

Downloading cordova library for wp8...
Download complete
Checking wp8 requirements...
[Error: Error while checking requirements: The command `msbuild` failed. Make sure 
you have the latest Windows Phone SDKs installed, AND have the latest .NET framework
added to your path (i.e C:WindowsMicrosoft.NETFrameworkv4.0.30319).
]

Adding the location of msbuild to the path indeed solved this issue. So the next step was to see if I can also add the orientation and geolocation plugins this way:

D:USERcordovacompass>cordova plugin add org.apache.cordova.device-orientation

Fetching plugin from "org.apache.cordova.device-orientation"...
Starting installation of "org.apache.cordova.device-orientation" for wp8
Preparing wp8 project
org.apache.cordova.device-orientation installed on wp8.

D:USERcordovacompass>cordova plugin add org.apache.cordova.geolocation
Fetching plugin from "org.apache.cordova.geolocation"...
Starting installation of "org.apache.cordova.geolocation" for wp8
Preparing wp8 project
org.apache.cordova.geolocation installed on wp8.

D:USERcordovacompass>

After issuing

cordova build wp8
cordova run wp8

it becomes apparent that on Windows Phone 8 installed testing on Lumia 920, if the frequency of monitoring the compass position is too high then the application freezes. The probability of it freezing seems to be directly related to the frequency in which you monitor the compass heading (either via getCurrentHeading or watchHeading). This is probably a problem with the plugin.

Hopefully, when monitoring the compass position every 1.2 seconds the application will be stable. Since the purpose is to have one codebase for all platforms, you should try and find the highest common denominator that will enable running the target application with the same code base on Android, iOS and WP8.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *