question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native Android: Network Request Failed (using localhost)

See original GitHub issue

Hey there,

I’ve been working on a React Native app for a while now with great success using Apollo Client. I do most of my debugging during development using the iOS simulator, and check the app on the Android emulator now and again to make sure things are working as intended.

I have configured Apollo Client per the docs (basically just setting the networkInterface and wrapping my app in the ApolloProvider) and it’s been working great on iOS. But when I booted up my Android emulator for my weekly check-up on the android side of things, all of my queries and mutations are resulting in:

Network error: Network request failed

My networkInterface is being pointed at: http://localhost:3000/graphql

This works on iOS, but Android can’t seem to communicate with it. After changing my network interface to a hosted endpoint (i.e. https://staging.app.com/graphql), it worked. It seems Android can’t communicate with localhost by default.

So, two things

  1. What can I do to enable communication with localhost during development? Is there something I can add to AndroidManifest.xml?
  2. Once we figure it out, this would be a great addition to the docs.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

21reactions
matthew-gordoncommented, Mar 16, 2018

So if you are going to use the android emulator, through android studio, using this uri… http://10.0.2.2:3000/ works for me… running on expo and through a physical device, need to track down your local ip address http://${ip.address}:3000/

10reactions
zackifycommented, Jun 2, 2017

Pretty sure just using the ip address of your computer instead of localhost will fix it. This has nothing to do with react-apollo btw 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native fetch() Network Request Failed - Stack Overflow
1) To find out the exact error in the logs, I first enabled 'Debug JS Remotely' using Cmd + M on the app...
Read more >
HTTP Fetch fails with "TypeError: Network request ... - GitHub
Localhost config is NEEDED from react-native for the bundling to work ... Network request failed when upload file to http not https with...
Read more >
Network Request Failed/Network Error in React Native using ...
It's just that simple! Start your app as usual but don't forget to give an IP address and a port, this will help...
Read more >
Improve "TypeError: Network request failed" error message
Network request failed, this error occurs usually when api call failed or you have some internet issue. In android emulator, sometimes this error...
Read more >
Networking - React Native
Many mobile apps need to load resources from a remote URL. You may want to make a POST request to a REST API,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found