Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run two react native applications?

I want to run my react native app twice: my device + simulator.

I don't mind using two metro bundler instances. How can I do that?

Right now, both my devices connect to 8081 - and whenever one connects, it kicks the other one off.

(I first built from XCode to my device/simulator, and then I run react-native start)

like image 541
TIMEX Avatar asked Jul 14 '18 07:07

TIMEX


2 Answers

  1. Install the App for the first time on your real ios device using npx react-native run-ios --device "Kasra’s iPhone", of course replace Kasra’s iPhone with the name of your real ios device.
  2. run npx react-native start --port 8082
  3. Open the app on ios real device and hit Ctrl + D to open the dev menu, or shake the device to open it.
  4. Select the Configure Bundler option
  5. For the IP, DO NOT USE 127.0.0.1, use the IP of your system, execute ifconfig or ipconfig in terminal to find your IP based on your OS.
  6. For the port number use 8082
  7. select Apply Changes, it should automatically start the app on your ios real device
  8. Now open another terminal window
  9. npx react-native run-ios to run it on your simulator.

Now you have two bundlers running side by side on ports 8081 and 8082 simultaneously.

like image 197
Kasra Avatar answered Sep 21 '22 17:09

Kasra


react-native run-ios command supports a port parameter after this commit. You can try to use this parameter to run your app in two different ports with two different builds.

From commit notes:

adds --port option to react-native run-ios as well as patches port …

Summary: The pull request adds the --port option to run-ios allowing a developer to build and launch a react-native app using a single command line like this: react-native run-ios --port 8088

It defaults to the current port 8081.

like image 29
bennygenel Avatar answered Sep 21 '22 17:09

bennygenel