简体   繁体   English

如何使用 Cordova 运行 Android 模拟器?

[英]How to run the Android Emulator with Cordova?

Prerequisite先决条件

  • Android SDK is well installed (directory : /Users/gamecube/Library/Android/sdk) Android SDK 安装好(目录:/Users/gamecube/Library/Android/sdk)

How to reproduce :如何重现:

  1. Run this command : cordova build android运行这个命令: cordova build android
  2. Run this command to launch android emulator : cordova emulate android --verbose运行此命令以启动 android 模拟器: cordova emulate android --verbose

Expected result预期结果

The emulator is launched.模拟器启动。

Obtained result得到的结果

Command finished with error code 0: /Users/gamecube/Desktop/geocars/platforms/android/gradlew cdvBuildDebug,-b,/Users/gamecube/Desktop/geocars/platforms/android/build.gradle
Built the following apk(s): 
    /Users/gamecube/Desktop/geocars/platforms/android/app/build/outputs/apk/debug/app-debug.apk
No scripts found for hook "before_deploy".
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/gamecube/Library/Android/sdk (DEPRECATED)
Running command: adb devices
Command finished with error code 0: adb devices
Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?
CordovaError: Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?
    at /Users/gamecube/Desktop/geocars/platforms/android/cordova/lib/emulator.js:176:35
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

My questions我的问题

Why Android Emulator does not work?为什么 Android 模拟器不起作用?

and

Why is there this error?为什么会出现这个错误? :

CordovaError: Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?

I solved my problem.我解决了我的问题。

How did I do it?我是怎么做的?

  • I opened Android Studio, and went to the SDK Manager.我打开 Android Studio,然后转到 SDK Manager。

图片

  • I clicked on the SDK Tools tab, and in the list displayed, I checked: Android SDK Command-line Tools (latest)我点击了 SDK Tools 选项卡,在显示的列表中,我检查了:Android SDK Command-line Tools (latest)

图片

  • I then clicked on Apply (then OK on the pop-up) to download the package in question.然后我点击应用(然后在弹出窗口中确定)下载有问题的包。

  • I added the path of avdmanager to PATH in my .bash_profile我在 .bash_profile 中将 avdmanager 的路径添加到 PATH

  • I have run source ~ / .bash_profile to refresh我已经运行source ~ / .bash_profile来刷新

  • And I launched my command: cordova emulate android --verbose successfully since the emulator has opened well.我启动了我的命令: cordova emulate android --verbose成功,因为模拟器已经打开了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM