flutter pub get 卡住了 (flutter pub get is stucking)


問題描述

flutter pub get 卡住了 (flutter pub get is stucking)

當我在終端運行時 flutter pub get 卡住了,它正在顯示

OS MacOS Catalina 10.15.3

Got TLS error trying to find package launch_review at https://pub.dartlang.org.                                    
pub get failed (server unavailable) ‑‑ attempting retry 1 in 1 second...                                           
Got socket error trying to find package launch_review at https://pub.dartlang.org.                                 
pub get failed (server unavailable) ‑‑ attempting retry 2 in 2 seconds...                                          
Got TLS error trying to find package launch_review at https://pub.dartlang.org.                                    
pub get failed (server unavailable) ‑‑ attempting retry 3 in 4 seconds...                                          
Got socket error trying to find package launch_review at https://pub.dartlang.org.                                 
pub get failed (server unavailable) ‑‑ attempting retry 4 in 8 seconds...                                          
Got socket error trying to find package launch_review at https://pub.dartlang.org.                              

參考解法

方法 1:

Quick fixes before explanation:

  • Restart your router! Works for me several times.
  • Make sure your network is not behind a proxy
  • Make sure you can ping to pub.dev without any packet loss
  • Try to close all of your dart.exe processes before retying to perform the flutter pub get
  • Try to delete an existing package from your pubspec.yaml and re‑get it to see if it works
  • Try to manually add the package to your project

So, I had (and sometime still having) the same issue. I've analyzed it and came to a conclusion that the package download manager and the server that hosts those packages aren't reliabe at all. Very small packages might just successfully be imported with "flutter pub get", whereas big ones might last forever to download. This is definately a networking issue, on either yours or their side.

Just for verificatioin that we are indeed experiencing the same issue:

  1. open your cmd (no matter t OS) and run: ping ‑t pub.dev .Now, if you see those inconsitent replies from the server, it means there's something wrong with the network (yours or their side). This looks something like this:

    enter image description here

  2. Open up your task manager and look for the latest dart.exe task (it should be invoked the moment you flutter pub get. This task is the package that is being downloaded. If you see the process size never exceeding a certain size, and the get command is still stuck, it only indicates a network issue and the package might never be downloaded successfully. For example, my attempts to get the carousela_flutter 1.4.1 package ended up with a halted process size of around 60mb, looks this this:

enter image description here

If you wait for a relatively large amount of time (10 minutes I would say is enough) and the connectivity issue is still not resolved, you will see the following msg from flutter: "Process finished with exit code 0".

I suggest you try another time or maually add the package.

p.s: it doesn't happen with all of the packages and from my investigation is seems to be related to the size of it. e.g, I managed to get the carousela_flutter 0.7.0 package, but the 1.4.1 failed.

方法 2:

In my case, The host of my ISP was blocked so it could not get the package and it was showing pub get failed (server unavailable) ‑‑ attempting retry 1 in 1 second...

So I turn on my VPN and tried once again and this time it was a success

方法 3:

502 Bad Gateway trying to find package package_name at https://pub.dartlang.org. If you click on the link, you'll find that the website is down. The same is also applied to https://pub.dev/. enter image description here

方法 4:

I´ve solved it on my Windows machine.

After many tries from answers in many discussions out there, I tried a lot of stuff, like:

  • Restarting the machine

  • Deleting the cache folder (the dart‑sdk download may be restarted)

  • Adding dart‑sdk in the Environment Variable Path

    X:\Dev\Flutter\bin\cache\dart‑sdk\

  • Adding dart‑sdk´s bin folder in the Path variable (for both Environment and User Variables) (desperate action, I know)

    X:\Dev\Flutter\bin\cache\dart‑sdk\bin

And still didn´t work.

BUT... I´ve found on this thread something about a proxy problem.

Then I´ve decided to try it out on my Windows machine, and it worked (finally).

Try typing this on Power Shell:

$Env:https_proxy="your.proxy.here:8080"

Then try flutter doctor again

enter image description here

方法 5:

If its a git error, use this command:

git config ‑‑global url."https://".insteadOf git://

More info here

(by YunusMagmusTanbirul HashanHasan El‑HefnawyAndré LeitãoProttay)

參考文件

  1. flutter pub get is stucking (CC BY‑SA 2.5/3.0/4.0)

#flutter-packages #Android #Flutter #flutter-dependencies






相關問題

使用顫振包有缺點嗎? (Is there a downside for using flutter packages?)

導入 Http/http.dart 包時出錯 (error in importing Http/http.dart package)

flutter pub get 卡住了 (flutter pub get is stucking)

在 Onboard Pages 上進行 Flutter 應用程序初始化? (Flutter app initialization at Onboard Pages?)

Flutter + FlutterFire 版本根據遷移指南使用 firebase_messaging 解決失敗的 firebase_remote_config (Flutter + FlutterFire version solving failed firebase_remote_config with firebase_messaging as per migration guide)

無法在 iOS 模擬器上使用顫振圖像選擇器選擇圖像 (Unable to select image using flutter image picker on iOS simulator)

Flutter Package:未壓縮的包存檔太大 (Flutter Package : Uncompressed package archive is too large)

我可以知道是否有一個顫振包可以在照片和圖紙上做標記和註釋? (May I know is there a flutter package to do markups and annotations on photos and drawings?)

使用音頻播放器包時出現顫振錯誤 (Flutter error when using audioplayer packages)

Flutter 上的 lib 中沒有包選擇 (There isn't package selection in lib on Flutter)

運行“flutter pub get”時在 google_maps_flutter 上解決 Flutter 版本失敗 (Flutter version solving failed on google_maps_flutter while running "flutter pub get")

顫振中甜甜圈圖表中的最高值弧 (Highlist highest value arc in donut chart in flutter)







留言討論