52

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.

hakki
  • 6,181
  • 6
  • 62
  • 106
  • It is happening to me but in iOS simulator... and ofcourse they are on same network, my xcode scheme is also set to debug, any solution to this? – dev1ce Sep 18 '22 at 07:49

26 Answers26

58

⚠️ 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

Azylaans
  • 981
  • 8
  • 18
26

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.

Vaibhav Saini
  • 269
  • 3
  • 3
  • 1
    `adb reverse tcp:8081 tcp:8081` did the trick for me. useful since sometimes my physical android device seems to lose connection. this is instant fix, as opposed to cleaning gradle and rebuilding android – Fre Timmerman Oct 26 '21 at 12:55
  • Usually, if I unplug the USB from my physical device, I would have to run `react-native `run-android` to make Metro connect which requires rebuilding the app. But thanks to you, running ADB reverses as above did the trick without having to rebuild, thanks! – Yuniac Aug 23 '22 at 12:52
23

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.

15

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:

Bundle Location Change Dialog

and they started to communicate with each other.

tidalwave
  • 186
  • 1
  • 5
  • This was exactly the case and i don't know why but application set its bundle location to `localhost:8081` in emulator device and the app was requesting js content from virtual device's localhost and that was the issue that causes the rapid disconnects. I changed the bundle location to `my-host-ip:8081` in the test app and it worked perfectly. – u.unver34 Jul 10 '22 at 01:29
9

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!

jsog
  • 896
  • 8
  • 10
6

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

Iroshana
  • 121
  • 1
  • 5
6

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

Burak
  • 667
  • 1
  • 11
  • 19
3

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 !

SuperGalou
  • 86
  • 4
2

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.

atoth
  • 838
  • 1
  • 9
  • 23
2

My problem is that the device is not connected to the internet. Throws the error. Try connecting stable internet connection.

Rushabh Shah
  • 680
  • 4
  • 22
2

When I remove network_security_config.xml and remove the following:

  `android:networkSecurityConfig="@xml/network_security_config"`

It works

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
Yusuf T.
  • 63
  • 4
1

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).

gignu
  • 1,763
  • 1
  • 14
  • 24
  • 1
    This works for me too sometimes, but the apps are listed alphabetically (I think it shows you the list of every process running on the app. – Yuniac Nov 29 '22 at 09:44
1

I tried everything and after running

adb reverse tcp:8081 tcp:8081
yarn android 

it worked.

Jakov Gl.
  • 361
  • 3
  • 11
1

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
Asad Shah
  • 41
  • 2
1

Sometimes it's a firewall / router issue - see if that's your problem:

  1. Find out the local IP address of your computer (where your Metro bundler / server is running).
  2. Open a browser from your phone.
  3. 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.

Yaron Budowski
  • 420
  • 5
  • 15
  • I was running into an issue where I was connected to a public network and I had to use a physical device (iOS) to test. Connecting my mac to my phone's network allowed the Metro to communicate properly. – impression7vx Nov 19 '22 at 20:51
  • Mine behaves the same whether connected to vpn or not. Sims have connection to metro, connected devices do not. idk – Mike S. Mar 07 '23 at 18:02
0
yarn start web

you can use this command to scan the QR code and see the app in you EXPO app at you mobile

spoorthi vaidya
  • 411
  • 5
  • 9
0

You musk permit local network in the application setting in iOS. Otherwise, Metro can not find your app even in the same network.

xiaolun
  • 23
  • 8
0

For me the solution was to remove the installed app and build run in Xcode again.

Patrik Rikama-Hinnenberg
  • 1,362
  • 1
  • 16
  • 27
0

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)

0

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.

Yuniac
  • 343
  • 3
  • 11
0

Easy solution ->

1- Go to Developer options of your phone . 2- Disable adb authorization timeout..

Now reload project and enjoy coding..

0

If you're on React Native 71 and using react-native-splash-screens, making your AppDelegate.mm like so

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure]; // If you're using react-native firebase

  self.moduleName = @"main";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  bool didFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
   
   [RNSplashScreen show];  // this needs to be called after [super application:application didFinishLaunchingWithOptions:launchOptions];
   
   return didFinish;
}
Uch
  • 94
  • 8
0

Sometimes, you get this error when one of the libraries defined in your code is not installed. This often occurs when creating a new environment and you forget to install one or more of the libraries used in your code.

Double-check each of your import statements , like the one below, against the list of libraries in the package.json file.

import { abc } from  "@react-navigation/def";

In addition, you might need to clean the environment:

npm start -- --reset-cache
cd android & gradlew clean & cd ..
Bilal Abdeen
  • 1,627
  • 1
  • 19
  • 41
0

In my scenario, I needed to wipe my virtual device (AVD). Steps:

  1. Open AndroidStudio
  2. I went into Virtual Device Manager
  3. In the Actions column, click on the 3 dots and finally 'Wipe Data'.
-1

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
masoud sharifi
  • 93
  • 5
  • 16
-1

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)

Meliodev
  • 9
  • 1