16

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

Uniruddh
  • 4,427
  • 3
  • 52
  • 86
Kiba
  • 10,155
  • 6
  • 27
  • 31

5 Answers5

25

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.

Chris Ghenea
  • 12,473
  • 1
  • 29
  • 36
  • 1
    None of that was actually very useful in my case. Have written an alternate answer based on my own (perhaps unique?) circumstances. Thanks anyhow. – arcseldon Dec 14 '15 at 12:09
  • 12
    For me on Ubuntu, using regular `android avd` and not Genymotion, only one that worked is CTRL + M. – Aleksandar Popovic Apr 29 '16 at 14:02
  • 5
    @AleksandarPopovic Many thanks for this shortcut! Only Ctrl+M works on my Windows 7 for Android Emulator – Alex Jun 02 '16 at 21:17
  • @alex , Ctrl + M doesn't work here in Android Studio, windows 10 .. DId you install anything extra for that ? – Shuvo Habib Aug 05 '16 at 21:33
  • 2
    @ShuvoHabib No, I'm using a default android emulator as usual – Alex Aug 08 '16 at 12:27
  • I am using LINUX ubuntu (Android) I have connected my device using USB cable. but I am not able to reload changes without running command for merging code into bundle I want live reloading using USB cable – Dinesh R Rajput Nov 25 '16 at 05:35
  • Thanks @Alex : Works fine for Windows – Dharam Mali Dec 27 '16 at 13:58
21

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

arcseldon
  • 35,523
  • 17
  • 121
  • 125
  • thanks for the shout out to my blog. I believe there's a genymotion button you can press to simulate a device shake. this should invoke the rage menu while the RN-APP is being emulated – Chris Geirman Dec 14 '15 at 14:23
  • @ChrisGeirman - thanks for your comment. Any idea what the genymotion button for simulating a device shake is? Or which keyboard shortcut it is? (I am using a Mac). – arcseldon Dec 15 '15 at 05:51
  • For me ⌘+M shortcut works. The only thing is that the menu button (appears on the black right sidebar of genymotion simulator) should appear on the screen to have the shortcut working. – Yasser Feb 27 '16 at 11:27
7

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

dsissitka
  • 981
  • 1
  • 5
  • 4
4

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!

enter image description here

Community
  • 1
  • 1
nazmul idris
  • 432
  • 6
  • 17
  • 1
    Hmm, in my case I needed to do `adb shell input keyevent 82 46 66 66` Otherwise it was not "clicking" on menu item. Anyway Thanks! – BlackTea May 02 '17 at 13:55
  • @BlackTea - I had to do the same. I updated my answer to reflect this. Here's a link to the actual shell script that's been working well for me - https://github.com/r3bl-alliance/react-native-weather/blob/master/android_rage_menu.sh – nazmul idris May 03 '17 at 14:33
0

On physical android device (e.g. 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