简体   繁体   中英

cmd : react-native run-android on every file change

when I run "react-native run-android" The build is deployed to emulator and the program executes fine. But after I make changes to the files locally, I need to run "react-native run-android".

Any way this can be done using watchman, like it happens for react-native ios.

Thanks

You have to enable live reloading.

According to the tutorial:

For Android, run react-native run-android from your projectto install the generated app on your emulator or device, and start the Node server which enables live code reloading. To see your changes you have to open the rage-shake-menu (either shake the device or press the menu button on devices, press F2 or Page Up for emulator, ⌘+M for Genymotion), and then press Reload JS.

I am using MacOS X, with Genymotion. For some reason, yet to be determined, everything worked, the simulator ran, and my app was deployed to it with "react-native run-android". However, the " rage menu " would not display when I tried using the Command + M keyboard shortcut indicated in the instructions here :

For Android, run react-native run-android from AwesomeProject to install the generated app on your emulator or device, and start the Node server which enables live code reloading. To see your changes you have to open the rage-shake-menu (either shake the device or press the menu button on devices, press F2 or Page Up for emulator, ⌘+M for Genymotion), and then press Reload JS.

So ultimately, I wrote a tiny shell script (you could just run the same command directly off the command line in bash shell etc) called rageMenuAndroid.sh as follows:

#!/usr/bin/env bash
adb shell input keyevent 82

This actually initiates the rage menu. From there it is simple to enable live reloading with React Native (my goal), just select " Auto Reload ", and select the " Reload JS " button whenever you want to refresh.

If anyone knows how to get the 'rage menu' to appear on the simulator directly please can they post a comment below. Getting IOS set up was a breeze, taking all of 2 mins, Android on the other hand was some effort (perhaps a couple of hours, and I already had a JDK installed).

Got inspiration for this answer from reading this blog

Open the rage shake menu. (F2/Page Up) -> Dev Settings -> Auto reload on JS change

For Android devices, I added a script that does the following to activate the rage menu. Basically presses "MENU" then "R" then "ENTER" (more info ADB Shell Input Events )

#!/bin/bash
adb shell input keyevent 82 46 66 66

Here's a link to the shell script that works pretty well for me - https://github.com/r3bl-alliance/react-native-weather/blob/master/android_rage_menu.sh . I use Webstorm, so I just added it as a "run target" which makes it so convenient to work with!

在此输入图像描述

On physical android device (eg Xiaomi Redmi 4) you press down menu button for one second and select "Enable Hot Reloading" option. Then you might need to re-start the development server with

react-native run-android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM