Flutter 卡在 package get 的解决办法

主要是天朝的原因,解决办法亲测有效(windows + Android Studio)

今天在尝试使用Flutter 的时候,需要使用一个第三方库

修改了 pubspec 文件之后,AS 像往常一样提示 需要 package get.

之前都听正常,不知道今天怎么了。

一直处在

Running "flutter packages get" in project_name...

的状态。

没关系我等,等了大概有10分钟吧,看了下 logcat

OS Error: 信号灯超时时间已到
, errno = 121, address = storage.googleapis.com, port = 60109
pub get failed (69) -- attempting retry 2 in 2 seconds...
OS Error: 信号灯超时时间已到
, errno = 121, address = pub.dartlang.org, port = 60352
pub get failed (69) -- attempting retry 3 in 4 seconds...
Got socket error trying to find package package_name at https://pub.dartlang.org.
pub get failed (69) -- attempting retry 4 in 8 seconds...
Got socket error trying to find package package_name at https://pub.dartlang.org.
pub get failed (69) -- attempting retry 5 in 16 seconds...
Got socket error trying to find package package_name at https://pub.dartlang.org.
pub get failed (69) -- attempting retry 6 in 32 seconds...

看来,应该是 storage.googleapis.com 撞墙了。

Google 搜索一下,原来flutter 已经有对策了。

Using Flutter in China

大概意思就是 把默认的 package 获取地址改为访问没有问题的镜像站就可以了。

具体操作

  • Linux 或 Mac
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  • Windows

新增两个环境变量即可

PUB_HOSTED_URL ===== https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL ===== https://storage.flutter-io.cn

执行一下 flutter doctor命令

下载在 package get 应该就没有问题了。

反正我是没问题了。

 
comments powered by Disqus