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

How to run the Android Emulator with Cordova?

先决条件

重现方法:

  1. 运行 这个命令:cordova build android
  2. 运行 此命令启动 android 模拟器:cordova emulate android --verbose

预期结果

模拟器已启动。

得到的结果

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)

我的问题

为什么Android模拟器不工作?

为什么会出现这个错误? :

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

我解决了我的问题。

我是怎么做到的?

  • 我打开了 Android Studio,然后转到 SDK 管理器。

  • 我点击了 SDK 工具选项卡,在显示的列表中,我检查了:Android SDK 命令行工具(最新)

  • 然后我点击应用(然后在弹出窗口中点击确定)下载有问题的包。

  • 我把avdmanager的路径加到我的.bash_profile

  • 我有运行source ~ / .bash_profile要刷新

  • 然后我启动了我的命令:cordova emulate android --verbose成功,因为模拟器已经打开。