React Native Android: Network Request Failed (using localhost)
See original GitHub issueHey 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
- What can I do to enable communication with
localhost
during development? Is there something I can add toAndroidManifest.xml
? - Once we figure it out, this would be a great addition to the docs.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
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 addresshttp://${ip.address}:3000/
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 😃