运行flutter doctor时HTTP主机可用性检测失败,求解决方案
Flutter Doctor HTTP主机无法访问的解决方案
1. 排查网络基础连接
- 直接用浏览器访问
cocoapods.org、maven.google.com、pub.dev、cloud.google.com,确认是否能正常打开。如果浏览器也无法访问,说明是网络本身的限制或故障。 - 切换网络环境(比如从WiFi换手机热点),排除局域网层面的访问限制。
2. 重置DNS配置
手动更换为公共DNS地址,解决域名解析失败问题:
- Windows:打开「网络和共享中心」→ 更改适配器设置 → 右键当前网络 → 属性 → 双击「Internet协议版本4(TCP/IPv4)」→ 选择「使用下面的DNS服务器地址」,填入
114.114.114.114或8.8.8.8。 - Mac:打开「系统设置」→ 网络 → 选中当前网络 → 高级 → DNS → 点击+号添加
114.114.114.114或8.8.8.8。 - Linux:编辑
/etc/resolv.conf文件,添加nameserver 8.8.8.8,保存后执行sudo systemctl restart nscd重启网络服务。
3. 处理代理设置
- 暂时关闭所有代理工具(系统代理、浏览器代理、第三方翻墙工具等),重新运行
flutter doctor检测。 - 若必须使用代理,需为Flutter配置代理环境变量:
- Windows命令行:
set HTTP_PROXY=http://代理地址:端口 set HTTPS_PROXY=http://代理地址:端口 - Mac/Linux终端:
export HTTP_PROXY=http://代理地址:端口 export HTTPS_PROXY=http://代理地址:端口
flutter doctor。 - Windows命令行:
4. 清理Flutter缓存
执行以下命令刷新依赖缓存:
flutter clean flutter pub get
完成后再次运行flutter doctor。
5. 检查hosts文件映射
- 打开hosts文件,确认目标域名没有被错误绑定:
- Windows路径:
C:\Windows\System32\drivers\etc\hosts - Mac/Linux路径:
/etc/hosts
- Windows路径:
- 删除所有涉及
cocoapods.org、maven.google.com、pub.dev、cloud.google.com的错误条目,保存文件(需管理员权限)。 - 刷新DNS缓存:
- Windows:
ipconfig /flushdns - Mac:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - Linux:
sudo systemctl restart nscd
- Windows:
内容的提问来源于stack exchange,提问作者Trust shine
相关产品推荐
相关产品推荐

