Home / GitHub Page

Unable to load script/could not connect to dev server - Android emulator

The application compiles without errors and the Android emulator is running properly.

However, when I run react-native run-android, I get the following error:

Screenshot_1563178727

After clicking reload I get another error message:

Screenshot_1563438477

Please note that the Metro Bundler is in fact running on port 8081. (Opening http://127.0.0.1:8081/ with a browser (or curl) gives me: React Native packager is running.)
I also tried the following without success (same error):

  • cleared all node_modules and all Android build files and started over
  • started metro server manually with npm start -- --reset-cache

However, I have no idea where this 10.0.2.2 ip address is coming from. (It’s not my local network, nor is the service running on that ip. It’s running on localhost.)

I’d appreciate any help.

I don’t know as I haven’t had this issue, but maybe on Stackoverflow you’ll get more answers since it’s a generic error.

I’ve spent hours on Stackoverflow and other web sites to research this. The only useful info was to use the statement react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res, which was the only way to get it working. And as you’ve already told me that’s not the solution.

I also tried to set the debug server to 127.0.0.1:8081, but this does not work either.

However, accessing http://127.0.0.1:8081/index.android.delta?platform=android&dev=true&minify=false on my host and within the emulator’s browser yields a response from the metro server.

I just hope that someone with react-native experience and this project might have an answer. I guess only time will tell. Until then, I will have to use this rather akward “bundle” workaround, which is detrimental to any real development work.

Hi Tessus,

You may find the below link useful as it helped me after hours of digging and stuck with similar issue.

For me the first one resolved the issue.
Enter below Command
adb reverse tcp:8080 tcp:8080 - just replace with your own port being used.

Thanks for the info, but react-native run-android already does the reverse command:

BUILD SUCCESSFUL in 28s
298 actionable tasks: 13 executed, 285 up-to-date
info Running /Users/tessus/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
info Starting the app on emulator-5554 (/Users/tessus/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am start -n net.cozic.joplin/net.cozic.joplin.MainActivity)...
Starting: Intent { cmp=net.cozic.joplin/.MainActivity }

I am running into the same issue, I initially got the application running by using

react-native run-android and it worked fine until I tried to reload the App.

I also tested this using the iOS simulator and it is working fine and behaving like a normal react-native app. It seems like this is connected to the Android App. I feel like the metro server is working fine there must be something wrong with the Android App.
I am a bit helpless on how to progress from here and there is not much information I can find for this.

I’ve recently made various changes to the build to get it working on Android 9 emulator. You might want to pull the last changes to see if it makes a difference.

1 Like

Man, whatever you did fixed it! Brilliant. Cheers.

Please @tessus hat did @laurent do… because I am also facing this problem and I can’t seem to figure out a solution

The following commit did it:

Here’s the relevant change:

diff --git a/ReactNativeClient/android/app/src/main/AndroidManifest.xml b/ReactNativeClient/android/app/src/main/AndroidManifest.xml
index 25d6b82f..8b00160c 100644
--- a/ReactNativeClient/android/app/src/main/AndroidManifest.xml
+++ b/ReactNativeClient/android/app/src/main/AndroidManifest.xml
@@ -34,6 +34,7 @@

        <application
                android:name=".MainApplication"
+               android:usesCleartextTraffic="true"
                android:allowBackup="true"
                android:label="@string/app_name"
                android:icon="@mipmap/ic_launcher"
diff --git a/ReactNativeClient/android/app/src/main/res/xml/network_security_config.xml b/ReactNativeClient/android/app/src/main/res/xml/network_security_config.xml
index 284be8c6..6b26a7cc 100644
--- a/ReactNativeClient/android/app/src/main/res/xml/network_security_config.xml
+++ b/ReactNativeClient/android/app/src/main/res/xml/network_security_config.xml
@@ -6,4 +6,10 @@
             <certificates src="user"/>
         </trust-anchors>
     </base-config>
+    <domain-config cleartextTrafficPermitted="true">
+        <domain includeSubdomains="true">localhost</domain>
+        <domain includeSubdomains="true">10.0.1.1</domain>
+        <domain includeSubdomains="true">10.0.2.2</domain>
+        <domain includeSubdomains="true">10.0.3.2</domain>
+    </domain-config>
 </network-security-config>

So, if you go back to my first post in this topic, you see an URL in the middle of the second screenshot:

http://10.0.2.2:8081/index.android.delta?platform=android&dev=true&minify=false

What does your URL say? You have add your IP address that shows up there to the file ReactNativeClient/android/app/src/main/res/xml/network_security_config.xml.

If that does not fix your issue, you have a different problem.

Edit: updated the file link