Whenever I run my RN-App via npx react-native run-android
the fetch requests are working perfectly fine. However, once I create a release build via
npx react-native run-android --variant=release
,
my App returns the error [TypeError: Network request failed]
whenever I try to fetch anything.
My fetch method looks like this:
try{
const res = await fetch('http://192.168.1.10:4000/api/');
const json = await res.json();
}catch(err){
console.log(err)
}
As others mentioned in similar questions, I have already tried adding
<application ... android:usesCleartextTraffic="true">...</application>
to AndroidManifest.xml
in android/app/src/main/
I also figured it might have something to do with Android apps not being allowed to run any requests without ssl in release mode, so I added a self signed SSL cert to my nodejs backend and tried again using https, without any success.
Any help is greatly appreciated since it’s my first time doing this!
2
Answers
As it turns out, the error lied in me not running the bundler when I changed something. Turns out you have to run it every time you make changes and want them to occur in the release build so I just ran the bundler with
and then created the release build via
and now it runs perfectly fine.
Try with network_security_config.xml file
create a file
network_security_config.xml
inres/xml
folder and add this code in the file.then add this line in your
AndroidManifest.xml
fileHope this works for you!