执行npx react-native run-android时出错

时间:2019-12-10 12:54:48

标签: react-native react-native-android

我是React Native的新手,正在尝试连接我的android设备,但显示以下错误。我在安装过程中可能犯了一些错误。我应该怎么做才能使模拟器启动?

    C:\Users\Bhavna>cd AwesomeProject

C:\Users\Bhavna\AwesomeProject>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 4 workers...
info JS server already running.
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...
> Task :app:installDebug FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
27 actionable tasks: 2 executed, 25 up-to-date

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 6s

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.bat app:installDebug -PreactNativeDevServerPort=8081

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 6s

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (C:\Users\Bhavna\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

3 个答案:

答案 0 :(得分:1)

在运行之前,您应该从android studio连接物理设备或启动模拟器 react-native run-android

> com.android.builder.testing.api.DeviceException: No connected devices!

答案 1 :(得分:1)

您应该检查是否在手机中启用了调试模式。 并遵循此。

export PATH=~/Library/Android/sdk/tools:$PATH
export PATH=~/Library/Android/sdk/platform-tools:$PATH

adb reverse tcp:8081 tcp:8081

adb shell input keyevent 82

第一个在您的终端中启用adb。 第二个onen启用8081端口。 如果运行第三个,则可以在应用程序中看到开发人员菜单。

答案 2 :(得分:1)

我尝试将选项从“为此设备充电”更改为“传输文件”,现在一切正常。谢谢大家!