flutter install_error ai_generated true

Pub get 失败(服务器不可用)-- 由于套接字异常无法解析包:OS 错误:连接被拒绝

Pub get failed (server unavailable) -- Could not resolve packages due to socket exception: OS Error: Connection refused

ID: flutter/install-error-pub-get-failed-socket

其他格式: JSON · Markdown 中文 · English
82%修复率
87%置信度
1证据数
2024-01-05首次发现

版本兼容性

版本状态引入弃用备注
flutter 3.10 active
flutter 3.22 active
dart 3.0 active
dart 3.5 active

根因分析

由于网络问题、防火墙阻止或 DNS 解析失败,pub.dev 服务器或自定义包仓库无法访问。

English

The pub.dev server or a custom package repository is unreachable due to network issues, firewall blocking, or DNS resolution failure.

generic

官方文档

https://dart.dev/tools/pub/troubleshoot

解决方案

  1. 检查网络连接并确保 pub.dev 可访问。临时禁用 VPN 或防火墙,然后运行 'flutter pub get --offline'(如果依赖已缓存),或使用镜像,设置 PUB_HOSTED_URL 为镜像地址。
  2. 使用不同的 DNS 服务器(例如 Google DNS 8.8.8.8)或在防火墙/代理设置中添加 pub.dev 的例外。

无效尝试

常见但无效的做法:

  1. Repeatedly running 'flutter pub get' without any network changes 95% 失败

    The underlying network issue persists; retrying does not resolve connectivity problems.

  2. Deleting the pubspec.lock file and running pub get again 85% 失败

    The lock file is not the cause; the error is network-related, so deletion has no effect.