运行 一个 react-native 项目导致 PC 死机

Running a react-native project causes PC to freeze

我一直在尝试着手进行 React Native 开发。我已经按照文档中的安装步骤进行操作,一切正常。但是,当我尝试 运行 应用 react-native run-android 时,我的模拟器死机了,我的整个 PC 也死机了,它几乎没有任何反应。

我试过使用我个人的 phone 而不是模拟器,但我得到了相同的结果。重装react native也没用

查看任务管理器,我看到磁盘使用率为 100% 左右。但我不认为我的 PC 旧或坏,这可能是问题所在吗?它真的需要 运行 的高规格吗?

如果有帮助,这就是我尝试 运行 时得到的结果:

C:\Users\Barak\AwesomeProject>react-native run-android info Starting

JS server... info Installing the app...

Task :app:installDebug 02:13:54 V/ddms: execute: running am get-config 02:13:54 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1 02:13:54 V/ddms: execute: returning Installing APK

'app-debug.apk' on 'Pixel_API_28(AVD) - 9' for app:debug 02:13:54

D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'

02:13:54 D/Device: Uploading file onto device 'emulator-5554' 02:13:54

D/ddms: Reading file permision of

C:\Users\Barak\AwesomeProject\android\app\build\outputs\apk\debug\app-debug.apk

as: rwx------ 02:13:54 V/ddms: execute: running pm install -r -t

"/data/local/tmp/app-debug.apk" 02:13:55 V/ddms: execute 'pm install

-r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 02:13:55 V/ddms: execute: returning 02:13:55 V/ddms: execute:

running rm "/data/local/tmp/app-debug.apk" 02:13:55 V/ddms: execute

'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1 02:13:55 V/ddms: execute: returning Installed on 1 device.

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 SUCCESSFUL in 1m 55s 27 actionable tasks: 2 executed, 25 up-to-date info Connecting to the development server... info Starting the app on "emulator-5554"... Starting: Intent { cmp=com.awesomeproject/.MainActivity } ^CTerminate batch job (Y/N)? y //You can see here I had to terminate it to get my PC to work again.

从您的问题来看,您的电脑可能不适合。我最近遇到了类似的问题并添加了额外的 RAM 修复了它。这并不意味着这是您问题的解决方案。该问题很可能与您的硬件有关,否则这将是一个常见问题。

干杯

我遇到了同样的问题。它 运行 在我的移动设备上,但它在一段时间后起作用了。尝试检查端口。

Run adb devices. Then  get your device name
run adb -s <device name> reverse tcp:8081 tcp:8081 

然后运行react-nativerun-android.