You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Android emulator should be able to reach web servers running on the host machine through the IP address `10.0.2.2`. This sometimes may not work due to firewall policies, VPN settings, or other environmental changes. If you are having trouble connecting to your local web server from an emulator, try these troubleshooting steps.
92
+
93
+
#### Make sure your application supports Internet connectivity
94
+
95
+
The Android manifest file should contain the following permission
If you are testing with an http server you may encounter an issue displaying a cleartext web page due to the default Android security settings. There are two ways to permit this content to load:
104
+
105
+
- Add `android:usesCleartextTraffic="true"` to your Android manifest `application` tag, or
106
+
- Create a more narrowly scoped [Network Security Config](https://developer.android.com/privacy-and-security/security-config#CleartextTrafficPermitted) that permits cleartext traffic on your specific test domain only.
107
+
108
+
#### Emulator network troubleshooting
109
+
110
+
If the local web server fails to load with errors like `net::ERR_CACHE_HIT` or `net::ERR_CONNECTION_REFUSED`, you may have network settings preventing the emulator/device from using Android’s loopback address. One way to confirm if this is your problem is to try loading your local web server from the emulator web browser.
111
+
112
+
Double check that your local web server is actually running, then open Chrome in the emulator and go to the URL for your web app. If it loads, then the issue is related to your app specifically. If it does not load, then the emulator as a whole is having issues connecting to the web server on your local machine through the virtual network.
113
+
114
+
:::note
115
+
116
+
Reminder: the emulator does not reach your local development machine through the `localhost` url, as this is the loopback address for the emulator virtual machine itself. The IP address for your local machine from the emulator is `10.0.2.2`.
117
+
118
+
:::
119
+
120
+
If you are unable to reach your web server, try creating a proxy connection through the Android Debug Bridge app (adb). This is done using the terminal. For example:
121
+
122
+
To link `localhost:8080` on your emulator to `localhost:8080` on your development machine, open the terminal and run:
This will create a proxy through to the emulator and should allow the web content to load on the emulator through `localhost:8080` in the emulator web browser. Since the Portals CLI tries to be helpful by changing `localhost` to `10.0.2.2` in your app dev-server setting, you can force the localhost IP in your app by setting the development server to `127.0.0.1`, such as:
0 commit comments