You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行flutter pub get遇socket错误:无法在pub.dev查找test包

报错信息

C:\flutter\bin\flutter.bat --no-color pub get
Running "flutter pub get" in flutter_tools...
Resolving dependencies in ..\..\..\..\flutter\packages\flutter_tools...
Waiting for another flutter command to release the startup lock...
Got socket error trying to find package test at https://pub.dev.
pub get failed
command: "C:\flutter\bin\cache\dart-sdk\bin\dart __deprecated_pub --directory ..\..\..\..\flutter\packages\flutter_tools get --example"
pub env: {
  "FLUTTER_ROOT": "C:\flutter",
  "PUB_ENVIRONMENT": "flutter_cli:get",
  "PUB_CACHE": "C:\Users\Anselemcrizy\AppData\Local\Pub\Cache",
}
exit code: 69

排查与解决步骤

  • 释放启动锁
    找到Flutter安装目录下的bin/cache/lockfile文件并删除,之后重新执行flutter pub get。

  • 验证网络连通性
    手动访问https://pub.dev确认可正常加载;若无法访问,切换网络环境(如热点)或检查代理设置是否正确;执行flutter doctor -v查看网络相关诊断信息。

  • 清理Pub缓存
    执行flutter pub cache clean清除损坏缓存,再重新运行flutter pub get。

  • 切换国内Pub镜像
    临时切换:执行flutter pub get --source=https://pub.flutter-io.cn
    永久配置:在系统环境变量中添加PUB_HOSTED_URL=https://pub.flutter-io.cn和FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn,重启终端后重试命令。

  • 更新Flutter与检查依赖
    执行flutter upgrade升级到最新稳定版;检查pubspec.yaml中test包的版本号是否合法,避免指定不存在的版本。

内容的提问来源于stack exchange,提问作者Anselem Chijioke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 16:42:07