William G.
William G.

Reputation: 413

How to run React Native app on Android Phone

I am building React Native app.

It is working well when I launch the app in terminal on Mac using "react-native run-android".

But when I got the apk file and installed it on another android device manually, it does not work.

It looks like this.

Crash on Huawei P8 lite

Upvotes: 29

Views: 129755

Answers (6)

Hakan
Hakan

Reputation: 613

You can try to use "npm run start" script.

Upvotes: 0

Brandon Stewart
Brandon Stewart

Reputation: 743

Get a list of all the devices:

adb devices

Then set the which device to run on:

adb -s <device name> reverse tcp:8081 tcp:8081

Then deploy the app:

react-native run-android

Upvotes: 4

Avnish Kumar
Avnish Kumar

Reputation: 61

Please find the below steps to run react-native code on a physical mobile device:-

  1. Please make sure you are on the same wifi network(Mobile and Laptop).
  2. Run your code and install it on the mobile through the Android Studio.
  3. The app will install and asking you to change your "dev settings".
  4. Shake your phone and go to "dev settings" and type your machine's IP address(192.16.XX.XXX:8081).
  5. Close the app once and open again, in the terminal you will see like this enter image description here

6. wait for a minute app will install and reflect the changes.

Upvotes: 3

Abraham
Abraham

Reputation: 9885

If you are connected via cable, do the following:

1. Goto > Settings > About Device

2. Then Software Info

3. Then > Build Number

4. Now Tap (Click) multiple times on Build Number to Enable Developer Options

5. Here you go not the Developer Options will be visible in your Settings

6. Now Go inside the Developer Options and Enable USB Debugging Mode.

7. Open your terminal

On Windows open Android SDK Manger > Platform Tools

Type:

$ adb devices

This will show you the devices and simulator/virtual-devices that you have on you computer.

8. Forward requests from your device

Type:

$ adb reverse tcp:8081 tcp:8081

9. Run it

Type:

$ npm run android

The app should appear on your device

Upvotes: 49

eremzeit
eremzeit

Reputation: 4566

If you've upgraded your version of react-native since generating your android project files, you might want to regenerate those now. I think you can use react-native upgrade.

Upvotes: 1

Zidail
Zidail

Reputation: 620

Looks like the source code in your APK is looking for the package server.

Read this on how to build APKs for react-native: React-Native - Generating Signed APK

If your devices is connected via cable:

  • If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device

Otherwise, you can still do this via Wifi by following the last point in the error:

  • If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server -e.g. 10.0.1.1:8081

Upvotes: 23

Related Questions