How do I "shake" an Android device within the Android emulator to bring up the dev menu to debug my React Native app
Within your app in the Android Emulator press Command + M on macOS or Ctrl + M on Linux and Windows.
With a React Native running in the emulator,
Press ctrl+m (for Linux, I suppose it's the same for Windows and ⌘+m for Mac OS X)
or run the following in terminal:
adb shell input keyevent 82
If you're using the new emulator that comes with Android Studio 2.0, the keyboard shortcut for the menu key is now Cmd+M, just like in Genymotion.
Alternatively, you can always send a menu button press using adb
in a terminal:
adb shell input keyevent KEYCODE_MENU
Also note that the menu button shortcut isn't a strict requirement, it's just the default behavior provided by the ReactActivity
Java class (which is used by default if you created your project with react-native init
). Here's the relevant code from onKeyUp
in ReactActivity.java
:
if (keyCode == KeyEvent.KEYCODE_MENU) {
mReactInstanceManager.showDevOptionsDialog();
return true;
}
If you're adding React Native to an existing app (documentation here) and you aren't using ReactActivity
, you'll need to hook the menu button up in a similar way. You can also call ReactInstanceManager.showDevOptionsDialog
through any other mechanism. For example, in an app I'm working on, I added a dev-only Action Bar menu item that brings up the menu, since I find that more convenient than shaking the device when working on a physical device.