首页 > 解决方案 > React Native 不适用于 Android 设备的“入门”指南

问题描述

我一直在尝试在我的 Windows PC 上启动并运行基本的 React Native 程序,但无法在通过 USB 连接的 Pixel 3 上加载它。我已将 Node.js 全新安装到 12.13.1。这是我做的时候得到的npx react-native run-android

PS C:\Users\davidc\Working\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 8 workers...
info Starting JS server...
* daemon not running; starting now at tcp:5037
* daemon started successfully
info Installing the app...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :app:installDebug
03:53:33 V/ddms: execute: running am get-config
03:53:33 V/ddms: execute 'am get-config' on '891X0457A' : EOF hit. Read: -1
03:53:33 V/ddms: execute: returning
Installing APK 'app-debug.apk' on 'Pixel 3 - 10' for app:debug
03:53:33 D/app-debug.apk: Uploading app-debug.apk onto device '891X0457A'
03:53:33 D/Device: Uploading file onto device '891X0457A'
03:53:33 D/ddms: Reading file permision of C:\Users\davidc\Working\AwesomeProject\android\app\build\outputs\apk\debug\app-debug.apk as: rwx------
03:53:34 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
03:53:37 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on '891X0457A' : EOF hit. Read: -1
03:53:37 V/ddms: execute: returning
03:53:37 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
03:53:37 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on '891X0457A' : EOF hit. Read: -1
03:53:37 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.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 32s
27 actionable tasks: 27 executed
info Connecting to the development server...
8081
info Starting the app on "891X0457A"...
Starting: Intent { cmp=com.awesomeproject/.MainActivity }
PS C:\Users\davidc\Working\AwesomeProject>

这就是我能做到的。我的手机说它无法加载脚本,并确保 Metro 服务器正在运行或 index.android.bundle 已正确打包。有什么建议么?

标签: androidreact-native

解决方案


我发现我遇到的问题源于 Metro 的一些代码与最新节点版本处理 RegEx 的方式不兼容。可以在此处找到临时解决方案。一旦解决了这个问题,我就可以运行此处提供的代码来构建丢失的 index.android.bundle。


推荐阅读