Cordova项目在Android手机中运行,但不在android studio模拟器中运行

时间:2018-02-08 07:41:01

标签: android cordova cordova-android

我正在尝试运行hello world cordova项目。 我可以在手机上运行这个项目但是当我尝试使用android studio模拟器运行时,它会抛出错误:

BUILD SUCCESSFUL in 2s
47 actionable tasks: 1 executed, 46 up-to-date
Built the following apk(s):
        C:\Users\vinay\AndroidStudioProjects\Cordova\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
ANDROID_HOME=C:\Users\vinay\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
No target specified, deploying to device '4172aa4d'.
none
Skipping build...
Built the following apk(s):
        C:\Users\vinay\AndroidStudioProjects\Cordova\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Using apk: C:\Users\vinay\AndroidStudioProjects\Cordova\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Package name: com.example.hello
LAUNCH SUCCESS

Android studio version-3.0.1,cordova 8.0.0版, 科尔多瓦要求

C:\Users\vinay\AndroidStudioProjects\Cordova\hello>cordova requirements
Android Studio project detected

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-27,android-26,android-25,android-24,Google Inc.:Google APIs:24,android-23,Google Inc.:Google APIs:23
Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-4.1\bin\gradle

请帮我找出我遗失的内容。

修改 Christian Wico 回复后更新:

我试图运行

cordova run android --emulator

现在又抛出了另一个错误

BUILD SUCCESSFUL in 2s
47 actionable tasks: 1 executed, 46 up-to-date
Built the following apk(s):
        C:\Users\vinay\AndroidStudioProjects\Cordova\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk
ANDROID_HOME=C:\Users\vinay\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
(node:10860) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: No emulator images (avds) found.
1. Download desired System Image by running: "C:\Users\vinay\AppData\Local\Android\Sdk\tools\android.bat" sdk
2. Create an AVD by running: "C:\Users\vinay\AppData\Local\Android\Sdk\tools\android.bat" avd
HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver

(node:10860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2 个答案:

答案 0 :(得分:0)

您的第一个代码组是SUCCESS消息。另一个是环境信息。 错误消息在哪里?

除非绝对需要使用Android Studio部署您的项目,您应该使用Cordova CLI启动您的应用

要启动,您可以在项目目录中管理以下命令:

cordova run android

该命令最好从连接的设备中启动应用程序。如果您希望明确告诉CLI启动模拟器,请使用--emulator标志和run命令:

cordova run android --emulator

答案 1 :(得分:0)

解决此问题的一种方法是重新启动模拟器。