在没有 运行 compile 命令的情况下,如何在 android 模拟器中观看 react native?

How can I watch in android emulator without running compile command in react native?

我已经多次更改我的代码。是否有像 "npm run watch" 这样的命令来观察实时变化并在 react-native 中为 android 编译代码和设计预览?

我假设您想要使用 'Live Reload' 或热重载。

每次您更新 Javascript 代码时,应用程序都会自动更新,无需手动重新加载。以下是启用方法以及有关差异的一些注释。

文档:http://facebook.github.io/react-native/docs/debugging

访问应用内开发者菜单

You can access the developer menu by shaking your device or by selecting "Shake Gesture" inside the Hardware menu in the iOS Simulator. You can also use the ⌘ + D keyboard shortcut when your app is running in the iOS Simulator, or ⌘ + M when running in an Android emulator on Mac OS and Ctrl+M on Windows and Linux. Alternatively for Android, you can run the command adb shell input keyevent 82 to open the dev menu (82 being the Menu key code).

正在重新加载JavaScript

您可以立即重新加载应用的 JavaScript 代码,而不是每次进行更改时都重新编译您的应用。为此,请从开发人员菜单中 select "Reload"。您还可以在 iOS 模拟器中按 ⌘R,或在 Android 模拟器上按 R 两次。

自动重新加载

You can speed up your development times by having your app reload automatically any time your code changes. Automatic reloading can be enabled by selecting "Enable Live Reload" from the Developer Menu.

You may even go a step further and keep your app running as new versions of your files are injected into the JavaScript bundle automatically by enabling Hot Reloading from the Developer Menu. This will allow you to persist the app's state through reloads.

有些情况下热重载无法完美实现。如果您 运行 遇到任何问题,请使用完全重新加载来重置您的应用。

You will need to rebuild your app for changes to take effect in certain situations: You have added new resources to your native app's bundle, such as an image in Images.xcassets on iOS or the res/drawable folder on Android. You have modified native code (Objective-C/Swift on iOS or Java/C++ on Android).