react-native: Network requests silently fail in Android since v0.63.0
Description
None of the network examples work in Android since v0.63.0; iOS is unaffected. Confirmed this is still an issue in v0.63.1 and v0.63.2 (the latest as of this report). Failures are silent and simply result in no data being returned to the view.
Since this is an issue with the network APIs, this affects all libraries that rely on those APIs, e.g., Apollo.
React Native version:
System:
OS: macOS 10.15.6
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory: 960.03 MB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.2 - /var/folders/tb/wx5d6rj53qjdg6sr4bmb1l840000gn/T/yarn--1597082804831-0.5290956210609348/node
Yarn: 1.22.4 - /var/folders/tb/wx5d6rj53qjdg6sr4bmb1l840000gn/T/yarn--1597082804831-0.5290956210609348/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
Languages:
Java: 11.0.8 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
- Install the last known good version:
npx react-native init AwesomeProject --version 0.62.2
- Replace the contents of
App.js
with one of the examples from the network docs, e.g., the Fetch Example. - Run the application in iOS.
npx react-native run-ios
- Note that the fetch example displays as intended.
- Run the application in Android.
npx react-native run-android
- Note that the fetch example displays as intended.
- Install latest (v0.63.2 as of this report):
npx react-native init AwesomeProject
- Replace the contents of
App.js
with one of the examples from the network docs, e.g., the Fetch Example. - Run the application in iOS.
npx react-native run-ios
- Note that the fetch example displays as intended.
- Run the application in Android.
npx react-native run-android
- Note that a blank screen is rendered.
Expected Results
The results should be rendered as they are on iOS and as they are on versions prior to v0.63.0. At the very least, would expect to see the activity indicator and possibly an error indicating the request failed.
Snack, code example, screenshot, or link to a repository:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28 (3 by maintainers)
More info: If we invoke Metro via
yarn
in our monorepo, it seems to “poison” the Metro cache. Runningyarn react-native --reset-cache
in the monorepo has no effect. We have to create a demo app with the same package name to clean it, e.g.,npx react-native init <ourproject> && cd <ourproject> && npx react-native start --reset-cache
, then the app works again. It appears Metro caches based on the project name, is that accurate?Also, while this workaround works for the development builds, the release builds still have no network connectivity, e.g.,
npx react-native run-android
works but notnpx react-native run-android --variant=release
.Edit: Running a release build also appears to “poison” the Metro cache.
@cristianoccazinsp Here is a Gist with the relevant code excerpt:
https://gist.github.com/danmaas/c60af5fed9f55d2bc616ce302696540d
This overrides the default OkHTTP client factory with a shim that intercepts DNS resolutions and sorts the result list to return IPv4 addresses before IPv6 addresses.
Hi,
I might have the same issue, did you mean that you can’t do any http request or socket connection with any server from your android application ? Because that’s exactly my situation, the android phone is connected but my RN android app can’t connect with my server.
Have a nice day