简体   繁体   English

react-native expo android macos问题

[英]react-native expo android macos issue

I am running into a issue with react-native app on android,我在 android 上遇到了 react-native 应用程序的问题,

  • app was built using expo应用程序是使用 expo 构建的

  • the app runs fine on iOS devices as well as iOS simulator该应用程序在 iOS 设备以及 iOS 模拟器上运行良好

  • running on android simulator, it give an warning at startup..在 android 模拟器上运行,它在启动时给出警告。

Possible Unhandled Promise Rejection (id: 0):可能未处理的 Promise 拒绝(id:0):

TypeError: Network request failed TypeError:网络请求失败

image of error from simulator is attached附上来自模拟器的错误图像

  • any subsequent calls to fetch hang with following error任何后续调用fetch挂起并出现以下错误

[Unhandled promise rejection: TypeError: Network request failed] [未处理的 promise 拒绝:TypeError:网络请求失败]

  • node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0 setTimeout$argument_0 中的 node_modules/whatwg-fetch/dist/fetch.umd.js:535:17
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer _callTimer 中的 node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers 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 __callFunction 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0 __guard$argument_0 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard __guard 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue 【原生代码】: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 fetch 调用是对 https 进行的,但是,在阅读了网上的几篇文章后,我在 app.json 中添加了以下内容,但没有效果

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

app dependencies from package.json are listed below下面列出了来自 package.json 的应用程序依赖项

  "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??关于可能是什么问题的任何帮助?

在此处输入图像描述

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 模拟器中运行的应用程序连接到 VPN 中的端点的人

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 Android 模拟器有自己的网络堆栈,如果您的应用程序尝试连接到 VPN 中的端点,您必须执行以下操作

  1. get an android device image that has google play store installed.获取安装了 Google Play 商店的 android 设备映像。

  2. download and install VPN tool of your choice on the Android image在 Android 映像上下载并安装您选择的 VPN 工具

  3. Start the VPN in the android emulator在android仿真器中启动VPN

  4. Now your app on the emulator can connect to protected VPN endpoints.现在,您在模拟器上的应用可以连接到受保护的 VPN 端点。

just having VPN running on your host machine is not enough, you need to run the VPN on the emulator itself...仅在您的主机上运行 VPN 是不够的,您需要在模拟器本身上运行 VPN...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM