I am about to set up a phonegap project and wanted to create a little hello world application to make sure my phonegap app works alright. For this I am printing out some device information. Here is my JavaScript code:
function onDeviceReady(){
document.getElementById("name").innerHTML = device.name; // undefined
document.getElementById("phonegap").innerHTML = device.phonegap; // undefined
document.getElementById("platform").innerHTML = device.platform; // Android
document.getElementById("version").innerHTML = device.version; // 4.4.2
document.getElementById("uuid").innerHTML = device.uuid; // 1dafa426...
}
/** Called at the bodys onLoad event */
function init(){
document.addEventListener("deviceready", onDeviceReady, false);
}
As soon as I run this code I get the following error message:
Unable to open asset URL: file:///android_asset/www/cordova_plugins.json
I have tried commenting out the device.name and device.phonegap lines, but this couldn't fix it.
Any ideas to fix this? I am using Cordova 2.9.0 and have attached both my config.xml file and my full error log.
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "..."
id = "io.cordova.helloCordova"
version = "2.0.0">
<name>Hello Cordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author href="..." email="dev@cordova.apache.org">
Apache Cordova Team
</author>
<access origin="*"/>
<!-- <content src="..." /> for external pages -->
<content src="index.html" />
<preference name="loglevel" value="DEBUG" />
<!--
<preference name="splashscreen" value="resourceName" />
<preference name="backgroundColor" value="0xFFF" />
<preference name="loadUrlTimeoutValue" value="20000" />
<preference name="InAppBrowserStorageEnabled" value="true" />
<preference name="disallowOverscroll" value="true" />
-->
<feature name="App">
<param name="android-package" value="org.apache.cordova.App"/>
</feature>
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker"/>
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.Device"/>
</feature>
<feature name="Accelerometer">
<param name="android-package" value="org.apache.cordova.AccelListener"/>
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.CompassListener"/>
</feature>
<feature name="Media">
<param name="android-package" value="org.apache.cordova.AudioHandler"/>
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher"/>
</feature>
<feature name="Contacts">
<param name="android-package" value="org.apache.cordova.ContactManager"/>
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.FileUtils"/>
</feature>
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.NetworkManager"/>
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.Notification"/>
</feature>
<feature name="Storage">
<param name="android-package" value="org.apache.cordova.Storage"/>
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.FileTransfer"/>
</feature>
<feature name="Capture">
<param name="android-package" value="org.apache.cordova.Capture"/>
</feature>
<feature name="Battery">
<param name="android-package" value="org.apache.cordova.BatteryListener"/>
</feature>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.SplashScreen"/>
</feature>
<feature name="Echo">
<param name="android-package" value="org.apache.cordova.Echo"/>
</feature>
<feature name="Globalization">
<param name="android-package" value="org.apache.cordova.Globalization"/>
</feature>
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser"/>
</feature>
<!-- Deprecated plugins element. Remove in 3.0 -->
<plugins>
</plugins>
</widget>
The CatLog:
D/CordovaWebView(8703): CordovaWebView is running on device made by: LGE
D/JsMessageQueue(8703): Set native->JS mode to 2
D/CordovaActivity(8703): CordovaActivity.init()
D/CordovaWebView(8703): >>> loadUrl(file:///android_asset/www/index.html)
D/PluginManager(8703): init()
D/CordovaWebView(8703): >>> loadUrlNow()
D/Config(8703): Unlimited access to network resources
I/CordovaLog(8703): Found start page location: index.html
I/CordovaLog(8703): Changing log level to DEBUG(3)
D/CordovaActivity(8703): Resuming the App
D/CordovaActivity(8703): CB-3064: The errorUrl is null
D/CordovaActivity(8703): onMessage(onPageStarted,file:///android_asset/www/index.html)
I/ActivityManager(770): Displayed sample/.HelloPhonegap: +254ms
E/AndroidProtocolHandler(8703): Unable to open asset URL: file:///android_asset/www/cordova_plugins.json
D/Cordova(8703): onPageFinished(file:///android_asset/www/index.html)
D/CordovaActivity(8703): onMessage(onPageFinished,file:///android_asset/www/index.html)
E/AndroidProtocolHandler(8703): Unable to open asset URL: file:///android_asset/www/cordova_plugins.js
EDIT (Workaround)
Creating a dummy file cordova_plugins.json helped me to get rid of my error messages. This seems just to be a little workaround and I still have got the problem that I cannot access the variables device.name and device.phonegap (They're undefined).
EDIT (Upgrade to Cordova 3.x)
After upgrading my project to cordova 3.x this error disappeared. Maybe I did just make any mistake in setting up the project. Nevertheless everything works totally fine with Cordova 3.x (I updated to 3.1 and later on to 3.4)