Phonegap - 无法打开资产URL:file:///android_asset/www/cordova_plugins.json

时间:2014-04-02 10:04:39

标签: javascript android json cordova

我即将设置一个phonegap项目,并希望创建一个小的hello world应用程序,以确保我的phonegap应用程序正常工作。为此,我打印出一些设备信息。这是我的JavaScript代码:

 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);
   }

运行此代码后,我收到以下错误消息:

  

无法打开资产网址:   文件:///android_asset/www/cordova_plugins.json

我试过注释掉device.name和device.phonegap行,但这无法修复它。

有什么想法来解决这个问题?我正在使用Cordova 2.9.0并附加了我的config.xml文件和我的完整错误日志。


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>

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

编辑(解决方法)

创建一个虚拟文件cordova_plugins.json帮助我摆脱了我的错误消息。这似乎只是一个小小的解决方法,我仍然遇到了无法访问变量device.name和device.phonegap(它们未定义)的问题。

编辑(升级至Cordova 3.x)

将我的项目升级到cordova 3.x后,此错误消失了。也许我在设置项目时犯了任何错误。然而,Cordova 3.x(我更新到3.1,后来更新到3.4)

,一切都运行得很好

0 个答案:

没有答案