运行React-Native项目的错误

时间:2019-06-28 13:01:16

标签: android react-native android-emulator avd

我开始学习React Native,我正在使用Linux(发行版Fedora 29),Java已在运行和运行,已经安装并配置了Android Studio(在android studio文档之后),我的环境变量与:

export ANDROID_HOME=/home/ghost/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

当我使用“ react-native run-android”运行项目时,出现以下错误:

[ghost@localhost mobile]$ react-native run-android
info JS server already running.
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)...
> Task :app:installDebug FAILED

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

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.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
26 actionable tasks: 1 executed, 25 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.

搜索时,我发现了一些提示,然后尝试重新启动adb,例如:

adb kill-server && adb start-server

即使我这样做,运行adb devices也无济于事

[ghost@localhost mobile]$ adb devices
List of devices attached

然后我尝试在android studio中运行(第三个图片网址),然后返回日志:

16:56   Gradle sync started
16:56   Project setup started
16:56   Gradle sync finished in 3 s 620 ms (from cached state)
**16:56 Emulator: statvfs('/home/ghost/.android/avd/Pixel_2_API_28.avd/snapshots/default_boot/ram.img') failed: No such file or directory
16:56   Emulator: ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy
16:56   Emulator: qemu-system-x86_64: failed to initialize KVM: Device or resource busy
16:56   Emulator: Process finished with exit code 0**

**可能包含有用信息的图像

SDK管理器:

我已安装的SDK平台 SDK Platforms that I have installed

我已安装的SDK工具 SDK Tools that I have installed

AVD管理器:

设备 Device

我已经尝试解决问题四天了,阅读文档本身,在论坛中搜索,重做设置。但是到目前为止,我还无法做到。预先感谢

3 个答案:

答案 0 :(得分:0)

cd android && ./gradlew clean

如果此命令不起作用,

您可能会检查android / gradlew上的权限

应该是755,而不是644

在应用程序根文件夹中运行chmod 755 android/gradlew 然后运行react-native run-android

它应该可以再次工作。

refer link

答案 1 :(得分:0)

使用USB将手机连接到计算机并启用android调试。

出了什么问题: 任务':app:installDebug'的执行失败。

  

com.android.builder.testing.api.DeviceException:没有连接的设备!

(您的手机未正确连接到PC。在Android设备上启用MTP模式)。

此命令
[ghost @ localhost mobile] $ adb设备
连接的设备列表

如果您的设备连接正确,应该输出类似这样的内容

adb设备
连接的设备列表
192.168.1.75:5555设备

答案 2 :(得分:0)

感谢大家的回答,它们使我非常有帮助!发生的问题是因为我在尝试启动android仿真器的同时正在运行vagrant,我发现在运行“ vagrant halt”并尝试再次运行android之后,在运行模拟器成为可能后,可以运行react-native项目