Thursday, 3 May 2012

PhoneGap (Cordova), fail to navigate to index.html

Noticed when debugging Windows Phone 7.1 or 7.5 Mango app made with PhoneGap (Cordova) 1.6.1. The same may apply to earlier versions. Visual Studio 2010.

Error 1: fails to build with the following error

Arg :: path to project\MyProject.csproj
path to solution\ MyProject\BuildManifestProcessor.js(14, 1) Microsoft JScript runtime error : Permission denied
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1036,5): error MSB3073: The command "CScript "path to project\ MyProject\/BuildManifestProcessor.js" " path to project\ MyProject\ MyProject.csproj"" exited with code -1.

Reason: CordovaSourceDictionary.xml in the root of the project is read-only. Happened because it was included in the project and then added to source control.
Fix: Make sure that CordovaSourceDictionary.xml is not read-only before doing the build

The file CordovaSourceDictionary.xml  is dynamic, generated on each build by a pre-build event

However, if this file is excluded from the project, you will experience

Error 2:  build succeeded, but debugging failed - after your project is built and installed in Windows Phone emulator, you see the error page with the message "We're having trouble displaying this page. We're having trouble with the page you're trying to reach and can't open it right now."

Studying output (or immediates) log in IDE reveals the following errors:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.dll
Updating IsolatedStorage for APP:DeviceID :: 7a37d1a9-bad8-49a9-a8cc-1bee764e65c1
GapBrowser_Navigating to :: /app/www/index.html
GapBrowser_NavigationFailed :: /app/www/index.html

Reason: When debugging, it tries to navigate to the default web page which is www\index.html and fails to do so.

Why? because it doesn't make it into the resulting .xap file

It appears that PhoneGap needs this file to be present, even though it is dynamically generated each time, on each build, by a prebuild event. In a pre-build event, it is executing BuildManifestProcessor.js

workaround 1:  make sure the file CordovaSourceDictionary.xml is present in your project folder before debugging, is not read-only and is included in the project as "Content". Check it out , if it is under source control.

better fix: I ended up with the pre-build event looking like this:

@echo off
IF EXIST "$(ProjectDir)CordovaSourceDictionary.xml" attrib -R "$(ProjectDir)CordovaSourceDictionary.xml"
CScript /nologo "$(ProjectDir)BuildManifestProcessor.js" "$(ProjectPath)"

No comments:

Post a Comment