【发布时间】: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