You'll need this in order to install your app on your device. First, make sure you have USB debugging enabled on your device.
Check that your device has been successfully connected by running adb devices
:
Seeing device in the right column means the device is connected. Android - go figure :) You must have only one device connected.
Now you can use react-native run-android
to install and launch your app on the device. If you get a "bridge configuration isn't available" error, see the Using adb reverse
section below.
Let's now set up an Android device to run our React Native projects.
First thing is to plug in your device and check the manufacturer code by using lsusb
, which should output something like this:
These lines represent the USB devices currently connected to your machine.
You want the line that represents your phone. If you're in doubt, try unplugging your phone and running the command again:
You'll see that after removing the phone, the line which has the phone model ("Motorola PCS" in this case) disappeared from the list. This is the line that we care about.
Bus 001 Device 003: ID 22b8:2e76 Motorola PCS
From the above line, you want to grab the first four digits from the device ID:
22b8:2e76
In this case, it's 22b8
. That's the identifier for Motorola.
You'll need to input this into your udev rules in order to get up and running:
Make sure that you replace 22b8
with the identifier you get in the above command.
Now check that your device is properly connecting to ADB, the Android Debug Bridge, by using adb devices
.
You can also iterate quickly on device using the development server. Follow one of the steps described below to make your development server running on your laptop accessible for your device.
Hint
Most modern android devices don't have a hardware menu button, which we use to trigger the developer menu. In that case you can shake the device to open the dev menu (to reload, debug, etc.). Alternatively, you can run the command
adb shell input keyevent 82
to open the dev menu (82 being the Menu key code).
Note that this option is available on devices running android 5.0+ (API 21).
Have your device connected via USB with debugging enabled (see paragraph above on how to enable USB debugging on your device).
adb reverse tcp:8081 tcp:8081
Reload JS
and other development options with no extra configurationLaunch the packager manually with react-native start --port [PORT]
For Android: Use the developer menu by clicking the menu button or shake. Select 'Debug server host & port for device' to set a different port.
For IOS: Edit the AppDelegate.m and change the line below to match the port number you're running:
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
adb shell input keyevent 82
from the command line.Dev Settings
.Debug server host for device
.ipconfig
to find your machine's IP address (more info).Reload JS
.You can edit the content above on GitHub and send us a pull request!
Recently, we have been working hard to make the documentation better based on your feedback. Your responses to this yes/no style survey will help us gauge whether we moved in the right direction with the improvements. Thank you!