Running On Device
It's always a good idea to test your app on an actual device before releasing it to your users. This document will guide you through the necessary steps to run your React Native app on a device and to get it ready for production.
If you used create-expo-app
to set up your project, you can run your app on a device in Expo Go by scanning the QR code that is displayed when you run npm start
. Refer to the Expo guide for running your project on your device for more information.
- Android
- iOS
Running your app on Android devicesβ
Development OSβ
- macOS
- Windows
- Linux
1. Enable Debugging over USBβ
Most Android devices can only install and run apps downloaded from Google Play, by default. You will need to enable USB Debugging on your device in order to install your app during development.
To enable USB debugging on your device, you will first need to enable the "Developer options" menu by going to Settings β About phone β Software information and then tapping the Build number
row at the bottom seven times. You can then go back to Settings β Developer options to enable "USB debugging".
2. Plug in your device via USBβ
Let's now set up an Android device to run our React Native projects. Go ahead and plug in your device via USB to your development machine.
Now check that your device is properly connecting to ADB, the Android Debug Bridge, by running adb devices
.
$ adb devices
List of devices attached
emulator-5554 offline # Google emulator
14ed2fcc device # Physical device
Seeing device
in the right column means the device is connected. You must have only one device connected at a time.
If you see unauthorized
in the list you will need to run adb reverse tcp:8081 tcp:8081
and press allow USB debugging on the device.
3. Run your appβ
From the root of your project; type the following in your command prompt to install and launch your app on the device:
- npm
- Yarn
npm run android
yarn android
If you get a "bridge configuration isn't available" error, see Using adb reverse.
Hint: You can also use the
React Native CLI
to generate and run arelease
build (e.g. from the root of your project:yarn android --mode release
).
Connecting to the development server
You can also iterate quickly on a device by connecting to the development server running on your development machine. There are several ways of accomplishing this, depending on whether you have access to a USB cable or a Wi-Fi network.
Method 1: Using adb reverse (recommended)β
You can use this method if your device is running Android 5.0 (Lollipop) or newer, it has USB debugging enabled, and it is connected via USB to your development machine.
Run the following in a command prompt:
$ adb -s <device name> reverse tcp:8081 tcp:8081
To find the device name, run the following adb command:
$ adb devices
You can now enable Live reloading from the Dev Menu. Your app will reload whenever your JavaScript code has changed.
Method 2: Connect via Wi-Fiβ
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Settings (or System Preferences) β Network.
- Make sure your laptop and your phone are on the same Wi-Fi network.
- Open your React Native app on your device.
- You'll see a red screen with an error. This is OK. The following steps will fix that.
- Open the in-app Dev Menu.
- Go to Dev Settings β Debug server host & port for device.
- Type in your machine's IP address and the port of the local dev server (e.g.
10.0.1.1:8081
). - Go back to the Dev Menu and select Reload JS.
You can now enable Live reloading from the Dev Menu. Your app will reload whenever your JavaScript code has changed.
Building your app for productionβ
You have built a great app using React Native, and you are now itching to release it in the Play Store. The process is the same as any other native Android app, with some additional considerations to take into account. Follow the guide for generating a signed APK to learn more.
1. Enable Debugging over USBβ
Most Android devices can only install and run apps downloaded from Google Play, by default. You will need to enable USB Debugging on your device in order to install your app during development.
To enable USB debugging on your device, you will first need to enable the "Developer options" menu by going to Settings β About phone β Software information and then tapping the Build number
row at the bottom seven times. You can then go back to Settings β Developer options to enable "USB debugging".
2. Plug in your device via USBβ
Let's now set up an Android device to run our React Native projects. Go ahead and plug in your device via USB to your development machine.
Now check that your device is properly connecting to ADB, the Android Debug Bridge, by running adb devices
.
$ adb devices
List of devices attached
emulator-5554 offline # Google emulator
14ed2fcc device # Physical device
Seeing device
in the right column means the device is connected. You must have only one device connected at a time.
3. Run your appβ
From the root of your project, run the following in your command prompt to install and launch your app on the device:
- npm
- Yarn
npm run android
yarn android
Hint: You can also use the
React Native CLI
to generate and run arelease
build (e.g. from the root of your project:yarn android --mode release
).
Connecting to the development server
You can also iterate quickly on a device by connecting to the development server running on your development machine. There are several ways of accomplishing this, depending on whether you have access to a USB cable or a Wi-Fi network.