HTTP Requests not Working in Android Pie React Native Issue Fix

Android Pie onwards Google has added a new layer of network security which allows only secured https requests and disable http requests by default. But no worries, you can enable http requests by using network security configuration feature.

First of all navigate to YourProject > android > app > src > main > res and create a folder named xml. Inside xml folder create a xml file named network_security_config.xml . Now copy paste the code given below to the file.

<?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config cleartextTrafficPermitted="true"> <trust-anchors> <certificates src="system" /> </trust-anchors> </base-config> </network-security-config>

The code given above allows all http requests. Now, refer the created xml file to Android Manifest file which is placed at YourProject > android > app > src > main > AndroidManifest.xml and add android:networkSecurityConfig property as given below.

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >

Now, just re-run your project using react-native run-android and http requests will be fine with Android Pie. If you want to know more about network security configuration in Android then click here.

Similar Posts

One Comment

Leave a Reply