I have a very weird issue that I am not able to solve. I am not sure how to Google this either because while I am familiar with React Native, I am not familiar with Android itself and not sure what my search term should be.
So, in my react native code, my client added the following network_security_config.xml
file under the android/app/src/main/res/xml
path:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">_my_clients_ip</domain>
</domain-config>
</network-security-config>
and consequently, they have added the following in the AndroidManifest.xml
file at android/app/src/main
path:
.
.
<application
.
.
android:networkSecurityConfig="@xml/network_security_config"
</application>
.
.
The dots above indicate other attributes and tags that I have omitted for brevity.
My issue
I am using an Android emulator to test my React Native app.
Until the above xml was NOT present, my react native app was functioning fine. However, with the above addition, when I start my react native app using commands (in 2 different terminals):
$ npx react-native start --reset-cache
$ npx react-native run-android
The app loads in the emulator - but it seems to be disconnected from the metro bundler (Terminal running npx react-native start --reset-cache
).
I try pressing r
key in this terminal to check if reloading works and it outputs:
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.
I am not sure why though. If I were to remove the android:networkSecurityConfig="@xml/network_security_config"
from the AndroidManifest.xml
, then all is well.
How do I resolve this?