首页 > 解决方案 > 错误无法启动模拟器。原因:没有找到模拟器作为 `emulator -list-avds` 的输出。在 Mac 中

问题描述

我正在建立一个Android开发环境。但是,执行环境存在问题。我已经完成了配置,但我一直说我找不到设备。但是,如果你运行服务器,然后在Android studio中运行它,它会正常工作。有什么问题?

bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
export PATH=${PATH}:$JAVA_HOME/bin
export ANDROID_PATH=/Users/myname/Library/Android
export PATH=$PATH:$ANDROID_PATH/sdk/platform-tools
export PATH=$PATH:$ANDROID_PATH/sdk/emulator
export PATH=$PATH:$ANDROID_PATH/sdk/tools
export PATH=$PATH:$ANDROID_PATH/sdk/tools/bin

但是错误

$ npx react-native run-android


info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon, 5 stopped Daemons could not be reused, use --status for details

> Task :app:stripDebugDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:installDebug

> Task :app:installDebug FAILED
27 actionable tasks: 9 executed, 18 up-to-date
[adb]: * daemon not running; starting now at tcp:5037
[adb]: * daemon started successfully

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s

error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
[adb]: * daemon not running; starting now at tcp:5037
[adb]: * daemon started successfully

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s

    at checkExecSyncError (child_process.js:611:11)
    at execFileSync (child_process.js:629:15)
    at runOnAllDevices (/Users/myname/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

有没有人和我有同样问题的人?

标签: react-nativeandroid-studioandroid-emulatorreact-native-android

解决方案


尝试以下操作:

> vim ~/.bash_profile

添加以下行:

export ANDROID_HOME=/Users/myname/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_PATH/emulator
export PATH=$PATH:$ANDROID_PATH/tools/bin

保存更改并重新启动终端。

运行 ADB,如果您遵循它,它将起作用。

> adb devices

List of devices attached

emulator-5554   device

推荐阅读