React Native run two different apps on two independent AVDs

51 Views Asked by At

I'm trying to run two different RN apps and debug it independently. But have problems. Two apps placed in different repos (folders). I created two Android Virtual Devices via Android Studio (deviceIds: "andr1" and "andr2").

In terminal I run: emulator -port 9988 -avd andr1 to start specific AVD for the first app on port 9988

When I have running AVD I run: react-native run-android --port=8081 --deviceId=emulator-9988 to run app on AVD with deviceId "emulator-9988". Logically seems that deviceId formed dynamically by port on which AVD is run

I think in a way that I have running AVD on port 9988 and Metro bundler on port 8081 and it should work. But this is how in looks after build process completed:

How it looks after build - screenshot

New external termanal with Metro is running and first terminal build process is finished. App is running but Metro not see changes and not update app.

Ok.. I run: emulator -port 9999 -avd andr2 and react-native run-android --port=8082 --deviceId=emulator-9999 for second app.

It works! For the first try in each AVD runs two independent apps. But they are not tracked by Metro bundler. If I want to update apps I need to run these two commands again: react-native run-android --port=8081 --deviceId=emulator-9988 react-native run-android --port=8082 --deviceId=emulator-9999

The question is - how I can use Metro bundler to update apps changes in realtime?

I try many instructions from Medium and etc but nowhere not found any acceptable solution.

======

dependencies: "react-native": "^0.71.6", "react-native-gradle-plugin": "^0.71.19",

1

There are 1 best solutions below

0
DukVanDuken On

Fixed! The problem was in ports.

I run:

adb -s emulator-9988 reverse tcp:9988 tcp:8081

adb -s emulator-9988 reverse tcp:9999 tcp:8082

This way a linked every AVD from their tcp ports 9988 and 9999 to metro bundler ports 8081 and 8082

This way debug apps can communicate with metro.