Error in reloading the application react native - react-native

i'm new in react native whenever i'm trying to reload the application i'm getting error on my emulator screen i.e could not connect to development server.i'm getting below error. Any help will be appreciated.

Try to open in your device browser the url: http://10.0.2.2:8081/index.delta (if it is responding go to step 2 - even with errors - if not go to 3).
Add the following line to your androidManifest.xml Application tag:
android:usesCleartextTraffic="true", rebuild your native app and test.
In a terminal run this command: adb reverse tcp:8081 tcp:8081

i had this problem too.
follow these steps in order
1.
try deleting your emulator and create a new one
then restart your pc
start react native & run android
if not solved
2.
connect an android phone via USB to your pc
turn on USB Debugging at your phone's setting
now start react native & run android

Related

Can't connect to standalone React Native Debugger

I've been having trouble getting the standalone React Native Debugger to work. I'm running an expo project and testing on android device. When I select Debug Remote JS, it opens up http://localhost:19000/debugger-ui/ in my web browser each time. My standalone debugger on port 19000 just says Waiting for React to connect. Not seeing any errors anywhere.
Make sure the device is connected via adb
adb devices
if you see your device, please run this command
adb reverse tcp:8097 tcp:8097
and restart your debugger

No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB

React Native app debug on real device has some problems;
My metro bundler console gives warn:
warn No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
warning and that cause real IOS device connection problem.
When I try to reload my react native app from Chrome React Native Debugger, it gives above warning and I can not debug my code from on Chrome
react-native: 0.62.2,
IOS: 13.6
It happens on Real device connection. When I work with IOS simulator, there is not problem.
NOTE: My phone and macbook on SAME wi-fi network.
So problem is not related to different wi-fi network usage.
⚠️ For iOS users :
Check that your build target is Debug :
Xcode Product => Scheme => Edit Scheme => Debug (and not release ! )
⚠️ For Android users :
I have found a solution that I posted on github.
Not the best but it could be useful:
First, you have to open MainApplication.java
and remove import com.facebook.react.BuildConfig;
Next, follow these steps :
# Reset metro bundler cache :
`npx react-native start --reset-cache`
# Remove Android assets cache :
`cd android && ./gradlew clean`
# Relaunch metro server :
`npx react-native run-android`
And see the magic 🎉
See here :
https://github.com/facebook/react-native/issues/29396
Running this worked for me for a Physical Android Device.
adb reverse tcp:8081 tcp:8081
or
npm run android-connect
If you face an error saying 'More than two devices are running', make sure that the emulators like BlueStacks are not running.
Your iPhone has to be connected to the same network (WiFi for example) as your Mac, because they have to communicate with each other (React Native Doc).
If it's already the case, then fill in the DCHP server manually on your iPhone and Mac, using Google's server (8.8.8.8), because it could be due to DHCP problems.
You may need to disconnect and reconnect to your Wifi.
For me I need to set the bundler location in my app from "localhost:8081" to "192.168.1.XX:8081" which is my computer's local IP address where Metro bundler runs on and the port is 8081.
If you don't know which port your bundler runs on you can specify it as a parameter like:
npx react-native start --port 8081
Then you need to specify the location in your development app. To do that:
Shake your device
Click change bundle location (I am on RN 0.64 it may differ in yours)
Give the bundler location of your computer's IP and port where Metro bundler runs on like:
and they started to communicate with each other.
My problem was that I was not connected to the same WiFi on my Mac and Iphone.I turned the wifi off and back on on both devices, and made sure both the mac and Iphone was connected to the same WiFi. Annoying, but true!
Your iPhone & mac must be connected to the same network. If both device connected to same network you must check local network availability for your app. (this happened to me on a iOS 14.0 running device).
check local network - iOS 14
Settings -> Privacy -> Local Network
On Android, this may also happen due to a problem with the network security config. If you do use the network security config, try removing the line android:networkSecurityConfig="#xml/network_security_config" from AndroidManifest.xml
My problem was that the emulator I was using had airplane mode turned on (because I tested related functionality). The problem resolved when I turned it off, thus enabling network to operate as usual.
My problem is that the device is not connected to the internet. Throws the error. Try connecting stable internet connection.
When I remove network_security_config.xml and remove the following:
`android:networkSecurityConfig="#xml/network_security_config"`
It works
I work on IOS environment, testing on an IPad that is USB connected.
I managed to fix this issue by adding the bundler address (127.0.0.1) in the ipad to reconnect
Shake the device (opens react native debug menu) > Configure Bundler > "127.0.0.1" in the first field
Hope this helps someone !
What did the trick for me was the following:
In Xcode go to Debug/Detach from YourAppName
Then reattach it by going to Debug/Attach to Process, select your app from the list (usually the first entry at the top).
I tried everything and after running
adb reverse tcp:8081 tcp:8081
yarn android
it worked.
What worked for me in this scenario was these steps
run server with --reset-cache
run npx jetify
open the project in adroid studio
go to refactor -> Migrate to AndroidX (this was the step that i was missing earlier)
start your emulator
run the app from android studio and it should work
Sometimes it's a firewall / router issue - see if that's your problem:
Find out the local IP address of your computer (where your Metro bundler / server is running).
Open a browser from your phone.
Open the IP address from #1 with port 8081 (e.g. http://192.168.0.42:8081).
If it's not loading -> it's a firewall / router issue.
A simple solution would be to connect the computer to the phone's hotspot.
yarn start web
you can use this command to scan the QR code and see the app in you EXPO app at you mobile
You musk permit local network in the application setting in iOS. Otherwise, Metro can not find your app even in the same network.
For iOS on Xcode:
Go to Window > Devices and Simulators, Go to "Installed Apps" section, Click on +, Pick your app , Run your code.
(This issue happened to me when I run the app after I uninstalled it from the device)
For me the solution was to remove the installed app and build run in Xcode again.
Oh, I had the same problem with RN - for me - there was a problem with connecting iphone to macbook server on localhost - and it solved if I just turned off wifi on macbook and then turned it on again. (Yes, it sounds weird - but it's a common problem)
For me, on IOS, Xcode would be stuck in debugging, a breakpoint is active and Metro can't reload because no apps are connected. To solve this:
open Xcode
In the left-hand side panel, click from the top row on Debug navigator (if it's not already focused and in the view like it was for me)
In the bottom pane (which can be minimized fully, in which case you have to hold and drag from the bottom of Xcode to expand it into view) you see a set of debugging buttons, the most left
one is a blue arrow-head-shaped button that continues/unpauses the script, click it.
after unpausing the script my app would connect to Metro.
Easy solution ->
1- Go to Developer options of your phone .
2- Disable adb authorization timeout..
Now reload project and enjoy coding..
My problem was that i added --variant=release
npx react-native run-android --variant=release
So i remove it and worked for me.Like this:
npx react-native run-android

The change on the code not reflected with React Native

I am developing a simple chat program with react native for learning purpose (not use expo). I made changes with the chat message (along with other code change) and was trying to reload the new message with USB debugging on Android device. But the app persistently shows the old message before change. Here is what I did:
Under android subdir, run .\gradlew clean
close android studio and react-native run-android again
Shake the device and choose reload
The #3 causes the error below:
Is there some module like nodemon for nodejs which picks up the code change nice and easily?
I often get this issue too. In this situation, I turn off the debug mode, and run adb reverse tcp:8081 tcp:8081 && react-native run-android again.
Connect your phone to your wifi, and try this,
Trigger the Developer Menu
Go to Dev Settings > Debug server host & port for device
Set it to <your_pc_ip_address_on_local_wifi>:8081. (If you are on a emulator, set it to localhost:8081)
Restart the app

[react-native]Could not connect to development server and unable to symbolicate stack trace(android)

I am new react native.i am developing a app which includes json data fetching by using axios. I made development connection through usb to my pc and app works fine but when i unplug the usb or close the react packager then there is a red screen on start of my app that says could not connect to development server.and then there is a error below in yellow bar that says unable to symbolicate stack trace...how can i get rid of these errors and run my app independently ?
I think according to your question you are closing the development server from commandline or cmd.
Once you disconnect you will have to restart the packager.
TO connect with Api
select the port number from API application url Example: http://localhost:44394
Step 1: Launch the emulator using command in terminal : npx react-native run-android
Step 2: open the app in emulator:
Step 3: enter the command in root terminal: adb reverse tcp:44394 tcp:44394

React Native Android Run

I am just starting with react native. I created my first app using React Native CLI. It was created without any errors. When I am trying to react-native run-android It ends up with this error as shown.
1) Run command " adb devices "
It will let you know if any device is connected or not
2) Try running by setting the Environment variable and proxy commands.
Follow this link: http://facebook.github.io/react-native/releases/0.38/docs/getting-started.html#content
first Start the android emulator.
From your react native folder run:
cd android && gradlew clean
THEN
cd .. && react-native run-android
Make sure you have your device connected to your computer, you can check that by running:
adb devices
if it's not connected, in your phone go to: settings > Developer Options > (enable) USB debugging.
Else if you want to run it from an emulator you will need to either install Genymotion, or AndroidStudio.
1) Run command adb devices to list all connected devices.
2) Then run command emulator #YOUR_DEVICE_NAME.
3) If adb devices will not show any devices then follow this link
http://facebook.github.io/react-native/releases/0.38/docs/getting-started.html#content
Have an android phone attached to your computer via USB cable and enable USB Debugging in the developer options. To get to the developer options open your About Phone and tap the version number several times.
Once it is in USB Debugging mode, run adb devices and a prompt will show up on your phone. Accept it and you should be good to go.
Another problem I had was I needed to path my SDK location, if you run into that then this will help: React Native android build failed. SDK location not found