0

I am setting up react native android for existing project. I followed instruction from Official getting started page. And I am able to open the app in in emulator when I run react-native run-android. The app is running perfectly. But the issue is, when I reload it using double clicking R key, it throws error Could not connect to development server.

enter image description here

Getting this error on Emulator and real device both

Solutions I have tried:

  1. Running real device and Macbook on same wifi.
  2. Setting macbook's IP address & port in Android device/Emulator in Dev Setting -> Debug server host & port for device
  3. Running adb reverse tcp:8081 tcp:8081

Still no luck.

When I open developer option using CMD + D and clicks on Debug JS Remotely, it throws different error: Unable to connect to remote debugger. CLEARTEXT communication to 192.x.x.x not permitted by network security policy.

In some cases it is showing "Connecting to remote debugger", but it is stuck there. enter image description here

Rahul Sagore
  • 1,588
  • 2
  • 26
  • 47

2 Answers2

3

This answer fixed my issue: https://stackoverflow.com/a/53158627/2630184

Seems like it was issue with Cleartext on Android Pie as I also mentioned this in question that cleartext error is getting displayed while clicking on Debug js remotely.

Adding android:usesCleartextTraffic="true" in AndroidManifest.xml, fixed this issue for me.

<application
    android:name="com.example.app"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">
Rahul Sagore
  • 1,588
  • 2
  • 26
  • 47
  • Please note that this can be a security issue and android:usesCleartextTraffic="true" should only be used in AndroidManifest.xml for debug purposes. In production, all information should be transferred via HTTPS. – Saulo M Aug 14 '19 at 16:27
0

Please, check if your device has an Internet connection. If Wi-Fi symbol has a cross with it, it means that there were some trouble with connection between MacOS and emulator. For me last time helped next steps:

1) Go to Mac > System preferences > Network > Advanced... > DNS.

2) Click to the + to add new DNS server.

3) Add 8.8.8.8 there.

4) Close your emulator and open it again. Check the connection and if the build is working

  • Hi, thanks. I did that change. Still not working. Same error. After sometime it is showing blank screen with green top bar "Connecting to to remote debugger". Not it is stuck there. This happened before as well. – Rahul Sagore Jul 04 '19 at 07:38
  • 1
    I've posted the answer: Adding `android:usesCleartextTraffic="true"` in AndroidManifest.xml fixed the issue. – Rahul Sagore Jul 04 '19 at 11:04