【问题标题】:react-native expo android macos issuereact-native expo android macos问题
【发布时间】:2021-03-25 14:25:00
【问题描述】:

我在 android 上遇到了 react-native 应用程序的问题,

  • 应用是使用 expo 构建的

  • 应用在 iOS 设备和 iOS 模拟器上运行良好

  • 在安卓模拟器上运行,启动时会发出警告..

可能的未处理承诺拒绝(id:0):

TypeError:网络请求失败

附上来自模拟器的错误图片

  • fetch 的任何后续调用都会挂起并出现以下错误

[未处理的承诺拒绝:TypeError:网络请求失败]

  • 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

fetch 调用是针对 https 进行的,但是,在阅读了网上的几篇帖子后,我将以下内容添加到 app.json 中,但没有效果

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

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"
  },

关于可能是什么问题的任何帮助??

【问题讨论】:

  • 请发布一个可重现的示例:stackoverflow.com/help/minimal-reproducible-example 我相信您正在向服务器发出网络请求,该服务器返回错误响应或由于某种原因您无法从您的 android 模拟器访问
  • 我正在调用 VPN 中的服务器,同时也在使用 sonicwall 在您的机器上运行 VPN

标签: android react-native networking expo vpn


【解决方案1】:

终于想通了……

这可能有助于其他人尝试从您在 Android 模拟器中运行的应用连接到 VPN 中的端点

Android 模拟器有自己的网络堆栈,如果您的应用尝试连接到 VPN 中的端点,您必须执行以下操作

  1. 获取已安装 google play 商店的 android 设备映像。

  2. 在 Android 映像上下载并安装您选择的 VPN 工具

  3. 在安卓模拟器中启动VPN

  4. 现在您在模拟器上的应用可以连接到受保护的 VPN 端点。

仅在您的主机上运行 VPN 是不够的,您需要在模拟器本身上运行 VPN...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 2020-01-31
    • 2022-12-22
    • 2020-10-09
    • 2019-05-09
    相关资源
    最近更新 更多