React Native 项目中执行 yarn android
命令运行项目,出现 Execution failed for task ':react-native-mmkv:downloadDoubleConversion'.
, javax.net.ssl.SSLException: Read timed out
等错误
如下效果
PS D:\code\AwesomeProject> yarn android
yarn run v1.22.17
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 898 file(s) to forward-jetify. Using 16 workers...
info Starting JS server...
info Installing the app...
> Task :react-native-mmkv:downloadBoost
Download https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz
> Task :react-native-mmkv:downloadDoubleConversion
Download https://github.com/google/double-conversion/archive/v1.1.6.tar.gz
> Task :react-native-mmkv:downloadDoubleConversion FAILED
43 actionable tasks: 28 executed, 15 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-mmkv:downloadDoubleConversion'.
> javax.net.ssl.SSLException: Read timed out
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10m 33s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-mmkv:downloadDoubleConversion'.
> javax.net.ssl.SSLException: Read timed out
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10m 33s
at makeError (D:\code\AwesomeProject\node_modules\execa\index.js:174:9)
at D:\code\AwesomeProject\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (D:\code\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5)
at async Command.handleAction (D:\code\AwesomeProject\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
出现这种错误时,一般是由于下载对应文件超时导致的,例如上面的例子中 https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz
地址国内可能正常访问不了,需要配置 VPN 后才能正常访问,但是有时即使设置了 VPN 但是部分站点可能链接不稳定,也会导致下载失败。
解决方案
如果某个包下载失败,导致 yarn android
中止,如果在浏览器单独访问下载失败的包可以下载的,可以多次执行 yarn android
命令一次次把需要的包下载下来就可以了。
如果某个包下载失败,但是包的下载地址在浏览器中也不能访问,可以尝试调整 VPN 模式试试,如 VPN 的 Global,Rule,PAC 等模式对于包下载效果也不一样。
重点
React Native 日常开发有个稳定快速的 网络
和 VPN
太重要了。