无法在cordova中运行Android - DeviceReady

时间:2015-07-02 05:01:41

标签: android cordova

我无法运行android的设备就绪功能(不会被解雇)。我如何解决它?我有目标sdk 22和cordova 5.1.1以及android studio 1.0.1。

我的index.html:

   <!DOCTYPE html>
<html>
<head>
    <title>Device Ready Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
</head>
<body onload="onLoad()">
</body>
</html>

index.js:

 function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

// device APIs are available
//
function onDeviceReady() {
    window.addEventListener("batterystatus", onBatteryStatus, false);
}

// Handle the batterystatus event
//
function onBatteryStatus(info) {
    console.log("Level: " + info.level + " isPlugged: " + info.isPlugged);
}

这会记录在哪里:console.log(&#34;级别:&#34; + info.level +&#34; isPlugged:&#34; + info.isPlugged);

如果我按命令提示运行:cordova build:

总时间:7.545秒

 C:\Users\salangar\hello\platforms\android\cordova\node_modules\q\q.js:126
                throw e;
                      ^
 Error code 1 for command: cmd with args: /s /c  "C:\Users\salangar\hello\platform
s\android\gradlew cdvBuildDebug -b           C:\Users\salangar\hello\platforms\android\build.gradle -Dorg.gradle.daemon=true"
 ERROR building one of the platforms: Error: cmd: Command failed with exit code 1

You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 1
   at ChildProcess.whenDone    (C:\Users\salangar\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:134:23)
   at ChildProcess.emit (events.js:110:17)
   at maybeClose (child_process.js:1015:16)
   at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

Logcat显示:

I/WebViewFactory﹕ Loading com.android.webview version 39 (1737576-arm) (code 300001)  
07-02 11:10:44.806    HelloWorld I/LibraryLoader﹕ Time to load native libraries: 726 ms (timestamps 7130-7856)
07-02 11:10:44.824    HelloWorld I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
07-02 11:10:44.979    HelloWorld V/WebViewChromiumFactoryProvider﹕ Binding Chromium to main looper Looper (main, tid 1) {951e68}
07-02 11:10:44.990    HelloWorld I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
  07-02 11:10:45.113    HelloWorld I/BrowserStartupController﹕ Initializing chromium process, singleProcess=true
  07-02 11:10:45.021    HelloWorld I/chromium﹕ [INFO:library_loader_hooks.cc(104)] Chromium logging enabled: level = 0, default verbosity = 0
    07-02 11:10:45.140    HelloWorld W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
07-02 11:10:45.448    HelloWorld W/AudioManagerAndroid﹕ Requires BLUETOOTH permission
07-02 11:10:45.575    HelloWorld W/chromium﹕ [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
07-02 11:10:45.590    HelloWorld I/chromium﹕ [INFO:aw_browser_main_parts.cc(65)] Load from apk succesful, fd=31 off=46184 len=3037
07-02 11:10:45.614    HelloWorld I/chromium﹕ [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.pak from, fd:32 off:229484 len:1089587
07-02 11:10:45.828    HelloWorld E/chromium﹕ [ERROR:gl_surface_egl.cc(165)] No suitable EGL configs found.
07-02 11:10:45.829    HelloWorld E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
07-02 11:10:45.835    HelloWorld E/chromium﹕ [ERROR:browser_main_loop.cc(988)] GLSurface::InitializeOneOff failed
07-02 11:10:46.790    HelloWorld W/chromium﹕ [WARNING:data_reduction_proxy_settings.cc(331)] SPDY proxy OFF at startup
07-02 11:10:47.032    HelloWorld W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
07-02 11:10:47.115    HelloWorld W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
07-02 11:10:47.328    HelloWorld D/SystemWebViewEngine﹕ CordovaWebView is running on device made by: unknown
07-02 11:10:47.408    HelloWorld W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
07-02 11:10:47.408    HelloWorld W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
07-02 11:10:47.712    HelloWorld I/art﹕ Background sticky concurrent mark sweep GC freed 3517(255KB) AllocSpace objects, 2(32KB) LOS objects, 31% free, 764KB/1117KB, paused 2.313ms total 499.804ms
07-02 11:10:48.445    HelloWorld D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
07-02 11:10:55.758    HelloWorld D/JsMessageQueue﹕ Set native->JS mode to OnlineEventsBridgeMode
07-02 11:10:56.152    HelloWorld I/art﹕ Background partial concurrent mark sweep GC freed 3730(208KB) AllocSpace objects, 1(16KB) LOS objects, 53% free, 887KB/1911KB, paused 1.825ms total 326.232ms
07-02 11:10:57.749    HelloWorld I/Choreographer﹕ Skipped 45 frames!  The application may be doing too much work on its main thread.
07-02 11:11:00.752    HelloWorld I/Choreographer﹕ Skipped 54 frames!  The application may be doing too much work on its main thread.
07-02 11:11:01.075    HelloWorld I/Choreographer﹕ Skipped 31 frames!  The application may be doing too much work on its main thread.
07-02 11:11:01.545    HelloWorld I/chromium﹕ [INFO:CONSOLE(1188)] "deviceready has not fired after 5 seconds.", source: file:///android_asset/www/cordova.js (1188)
07-02 11:11:01.750    HelloWorld I/chromium﹕ [INFO:CONSOLE(1181)] "Channel not fired: onPluginsReady", source: file:///android_asset/www/cordova.js (1181)
 07-02 11:11:01.752    HelloWorld I/chromium﹕ [INFO:CONSOLE(1181)] "Channel not fired: onCordovaReady", source: file:///android_asset/www/cordova.js (1181)
  07-02 11:11:03.655    HelloWorld W/PluginManager﹕ THREAD WARNING: exec() call to CoreAndroid.show blocked the main thread for 161ms. Plugin should use CordovaInterface.getThreadPool().
07-02 11:11:04.699    HelloWorld I/chromium﹕ [INFO:CONSOLE(47)] "Received Event: deviceready", source: file:///android_asset/www/js/index.js (47)
 07-02 11:11:27.708    HelloWorld I/Choreographer﹕ Skipped 33 frames!  The application may be doing too much work on its main thread.
 07-02 11:11:28.112    HelloWorld I/Choreographer﹕ Skipped 34 frames!  The application may be doing too much work on its main thread.
07-02 11:11:58.646    HelloWorld I/Choreographer﹕ Skipped 33 frames!  The application may be doing too much work on its main thread.

1 个答案:

答案 0 :(得分:1)

  1. 设备就绪功能(未被触发)。我该如何解决?
  2. 您无需使用onLoad()函数来调用deviceready事件。 而不是: -

    function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
    }
    

    写道: -       document.addEventListener(“deviceready”,onDeviceReady,false);

    另一件事是你需要在body标签内编写脚本cordova.js部分并添加index.js文件,如cordova.js。

    1. 将记录在哪里:console.log(“Level:”+ info.level +“isPlugged:”+ info.isPlugged);
    2. 此日志以logcat打印。

      希望这有帮助:)如果您有任何困难,请告诉我。