簡體   English   中英

無法運行Android-Cordova中的DeviceReady

[英]Unable to run Android - DeviceReady in 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(“ Level:” + info.level +“ isPlugged:” + 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. 設備就緒功能(不觸發)。 我如何解決它?

您不需要使用onLoad()函數來調用deviceready事件。 代替這個:-

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

只需編寫:-document.addEventListener(“ deviceready”,onDeviceReady,false);

另一件事是,您需要在body標簽內編寫腳本cordova.js部分,並像cordova.js一樣添加index.js文件。

  1. 這將記錄在哪里:console.log(“ Level:” + info.level +“ isPlugged:” + info.isPlugged);

該日志在logcat中打印。

希望對您有所幫助:)如果您有任何困難,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM