0
votes

I am running into a issue with react-native app on android,

  • app was built using expo

  • the app runs fine on iOS devices as well as iOS simulator

  • running on android simulator, it give an warning at startup..

Possible Unhandled Promise Rejection (id: 0):

TypeError: Network request failed

image of error from simulator is attached

  • any subsequent calls to fetch hang with following error

[Unhandled promise rejection: TypeError: Network request failed]

  • node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

the fetch call is made to https, however, after reading several posts on the net I added the following to the app.json with not effect

"android": {
   "UsesCleartextTraffic": "true"
}

app dependencies from package.json are listed below

  "dependencies": {
    "@react-native-community/hooks": "^2.6.0",
    "expo": "~39.0.2",
    "expo-status-bar": "~1.0.2",
    "graphql": "^14.7.0",
    "graphql-request": "^3.3.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-39.0.4.tar.gz",
    "react-native-maps": "^0.27.1",
    "react-native-web": "~0.13.12"
  },

any help on what may be the issue ??

enter image description here

1
please post a reproducible example: stackoverflow.com/help/minimal-reproducible-example i believe you are making a network request to a server that returns an error response or that you cannot reach from your android emulator for some reasonbrentvatne
I am making a call to a server that is in VPN, also running VPN on y machine using sonicwallsatyendra

1 Answers

0
votes

finally figured this out...

this may help others who are trying to connect to an endpoint in a VPN from your app running in Android emulator

Android emulator has it's own networking stack, if your app is trying to connect to an endpoint in a VPN, you will have to do the following

  1. get an android device image that has google play store installed.

  2. download and install VPN tool of your choice on the Android image

  3. Start the VPN in the android emulator

  4. Now your app on the emulator can connect to protected VPN endpoints.

just having VPN running on your host machine is not enough, you need to run the VPN on the emulator itself...