React Native 不适用于 Android 设备的“入门”指南

Posted

技术标签:

【中文标题】React Native 不适用于 Android 设备的“入门”指南【英文标题】:"Getting Started" Guide for React Native Not Working with Android Device 【发布时间】:2020-03-15 14:33:52 【问题描述】:

我一直试图在我的 Windows PC 上启动并运行 basic React Native program,但无法在通过 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 已正确打包。有什么建议吗?

【问题讨论】:

【参考方案1】:

我发现我遇到的问题源于 Metro 的一些代码与最新节点版本处理 RegEx 的方式不兼容。临时解决方案可以是found here。修复后,我就可以运行代码 provided here 来构建丢失的 index.android.bundle。

【讨论】:

以上是关于React Native 不适用于 Android 设备的“入门”指南的主要内容,如果未能解决你的问题,请参考以下文章

React Native StatusBar:黑暗内容不适用于android

react-native-push-notification - 本地通知不适用于 Android

React Native 不适用于 Android 设备的“入门”指南

Intl 在 React Native 中不适用于 Android

反应本机状态栏不适用于android中的反应导航

Expo LAN 配置不适用于新的 React Native 项目