React Native Android App run on emulator doesn't connect to metro bundler when installed using android-studio - react-native

My React-Native(0.68.1) project runs properly on my emulator when using npx react-native run-android command and everything works fine with the metro bundler instance created by this command.
Only when I run project from android studio (2021.3.1 Patch 1) , app is build successfully and installed on emulator, but cannot connect to metro bundler (which I separately run using npx react-native start command).
I wanted to try and update the debug server & port as mentioned in other similar questions , but I cannot access the debug app menu even after dismissing the error (menu doesn't show when ipress the shortcut)
Issue also occurs on build installed on emulator via npx react-native run-android when I close the app and metro bundler created by the command and start a separate metro bundler. In this case but I am able to enter settings menu and enter "debug server and port " to 10.0.2.2:8081 and app connects to metro.
I am using mac mini m1.

To fix this issue
first of all, start your emulator and run adb reverse tcp:8081 tcp:8081 this command on the terminal and then run npx react-native start and then run your project in the android studio and it will automatically link your app to that bundle

Related

No apps connected. Sending "devMenu" to all React Native apps failed

This is a strange error when I ran React Native (0.63.2) app on Android 8.1 emulator with
npx react-native run-android
Here is the full warning message:
warn No apps connected. Sending "devMenu" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Opening developer menu...
Tried adb reverse tcp:8081 tcp:8081 but didn't help. The emulator was working fine. What can go wrong here?
Note: Answer targets only those visitors, who are facing this issue after successfully running once on device
npx react-native run-android
//once its installed on device next time just do
npx react-native start
installs app at your device on first run. I was facing same issue only when I tried npx react-native run-android second time.
So I used npx react-native start then
I just opened my latest app installed by last run and its working and showing me the updates as well

React Native Android Studio Emulator launch issue

When I try to start my react-native init project with this command npx react-native start nothing happens in the emulator.
enter image description here
Command npx react-native start is for starting up the bundler (Metro)
to run it on an android emulator or device you need npx react-native run-android.
Before that please make sure you have either a real device connected or an emulator ready.
You can follow or check by using this guide for your Android environment setup.

Getting Building iOS bundle error when trying to build an android app - expo -react-native

I was able to build app using expo build:android previously. However, after upgrading to latest expo version I get following error:
connect ECONNREFUSED 127.0.0.1:19001
Set EXPO_DEBUG=true in your env to view the stack trace.
I also see the following lines in the log:
Publishing to channel 'default'...
Building iOS bundle
I don't added ios to my app.json, I only need to build an android apk. To do that I use expo build:android -t app-bundle
I also removed package-lock.json and node_modules and run npm install, but I get the same error.
I run expo start on another cmd and then run expo build:android -t app-bundle still get same error
Also when I clear expo cache, see the following log:
Restarting Metro Bundler...
Starting Metro Bundler on port 19001.
Couldn't adb reverse: adb.exe: error: Invalid source port: 'undefined'
I had faced same issue myself and found the solution. Expo is looking for localhost:19001 which is not running. Just follow following steps and it should work as expected:
Run expo start no terminal and once it opens up the
browser where you will find this line written Starting Metro
Bundler on port 19001.
Now open another terminal instance and run expo build:android.

How to show metro bundler in new terminal when execute react-native run-android?

the command react-native run-android not opening metro bundler in new terminal on ubuntu. it only show starting js server and other react-native messages, and the app run normally.
when I tried it on windows or mac, metro bundler always opened in new terminal whenever I run react-native run-android and the port is available.
I am using ubuntu 16.04, react-native 0.57.8
what should I add to the command to make it behave like on windows or mac?
I am expecting it will run metro bundler in new terminal on ubuntu just like on windows or mac. thanks.

How to open and run React-Native app?

I'm new to React and React-Native I'm trying to open a React-native app I cloned from github. I've done a npm install and I did a npm start in the command line. It says: "Running Packager on port 8081" and then a bunch of other builds beneath it. I tried going to local host 8081 and 8081/hot but I can't see the app. Does anyone know how to run and test an react-native app on the browser?
follow the below step
1) Go to project directory
after use this CLI
2) react-native run-android
it can run only either emulator or real device so we can first start the emulator after the try above command
more details see this doc
Inside your project directory for bundle js.
3) react-native start
or
3) react-native start --reset-cache
After installing packages,
open src folder--->open in terminal
--->$ npm start
react-native run-ios --simulator="iPhone 5s"
If you have an installation with android and ios folders, you should run yarn android or yarn ios.