今天在嘗試使用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 已經有對策了。
大概意思就是 把默認的 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 應該就沒有問題了。
反正我是沒問題了。