Axios request works on iOS or in a browser but fails on Android with Network Error
AxiosError: Network ErrorShort answer
A React Native app has no CORS, so on Android a Network Error usually means the request never reached the server. Inside the emulator localhost is the emulator itself, so use 10.0.2.2. Since API 28 plain http is blocked unless you allow it. A phone must use your computer's LAN address.
Fix it fast
1Find out which cause you have
Print the exact URL the app calls, then open that same URL from where the app runs: the emulator browser, or the phone's browser. If the page does not load there, the cause is networking, not Axios.
// in the failing call console.log(axios.defaults.baseURL);2Match what you see, then jump to its fix
- 1
The baseURL is http://localhost:3000 or http://127.0.0.1:3000 and only Android failslocalhost points at the Android emulator, not at your computerFix - 2
The URL starts with http:// and the same call to an https:// URL worksPlain http:// is blocked: cleartext traffic is off by default since Android 9Fix - 3
Works in the emulator with 10.0.2.2, fails on the phoneA real phone cannot reach the address you useFix
- 1
What does the error look like?
AxiosError: Network Error
Cause 1 of 3
localhost points at the Android emulator, not at your computer
1Check
Android's emulator docs say 127.0.0.1 is the emulated device's own loopback. Your computer's loopback is reached with the special address 10.0.2.2.
grep -rn "localhost\|127.0.0.1" src/2Fix
Use 10.0.2.2 for the emulator, or forward the port from the emulator to your computer with adb reverse and keep localhost.
// emulator only
const baseURL = 'http://10.0.2.2:3000';
# or keep localhost and forward the port:
adb reverse tcp:3000 tcp:30003Verify
The same request now returns data in the emulator.
adb devicesConfirmed by developer.android.com
Cause 2 of 3
Plain http:// is blocked: cleartext traffic is off by default since Android 9
1Check
React Native's network guide says cleartext traffic is blocked by default as of API level 28. Android's network security guide says the same and shows how to allow it.
grep -n "usesCleartextTraffic\|networkSecurityConfig" android/app/src/main/AndroidManifest.xml2Fix
Best fix: serve the API over https. For development only, allow cleartext for your dev host in a network security config and point the manifest at it.
<!-- android/app/src/main/res/xml/network_security_config.xml -->
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
<!-- AndroidManifest.xml, on the <application> tag -->
android:networkSecurityConfig="@xml/network_security_config"3Verify
Rebuild the app (a manifest change needs a native build) and repeat the request.
npx react-native run-androidConfirmed by developer.android.com
Cause 3 of 3
A real phone cannot reach the address you use
1Check
10.0.2.2 exists only inside the emulator. A phone needs an address it can reach: your computer's LAN address on the same Wi-Fi, or a USB port forward.
# computer LAN address: macOS System Settings > Network, Windows ipconfig
adb devices2Fix
Point the baseURL at your computer's LAN address, with phone and computer on the same Wi-Fi. Or forward the port over USB with adb reverse and use localhost.
const baseURL = 'http://192.168.1.20:3000'; // your computer's LAN address
# or over USB:
adb reverse tcp:3000 tcp:30003Verify
Open the same URL in the phone's browser first, then run the app.
adb devicesConfirmed by reactnative.dev
How do I stop it coming back?
- Keep the API base URL in one config file and set it per target: emulator, phone, production.
- Use https for every environment except a local dev server.
- Log error.code and error.message in the catch block so a Network Error is not all you see.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixMobile apps
Axios returns Network Error in a React Native app on iPhone or the iOS Simulator
error.code is ERR_NETWORK and error.response is undefined
A Network Error means iOS stopped the request before any HTTP answer came back.
3 causes, each with a fixMobile apps
backgroundImage: url(...) does nothing in a React Native view
ImageBackground renders an empty area
In React Native the backgroundImage style draws linear and radial gradients, not pictures, so url(...) is ignored.
3 causes, each with a fixMobile apps
A custom font in React Native falls back to the system font
Unrecognized font family 'MyFont'
React Native does not report a missing font, it just draws the system font.
6 causes, each with a fixMobile apps
fetch fails with TypeError: Network request failed in React Native
Network request failed
Network request failed means the request never got an HTTP response, so there is no status code to read.
3 causes, each with a fixMobile apps
react-native-geolocation-service getCurrentPosition fails or never returns
Location provider not available
Read the error code in the callback.
5 causes, each with a fix