"flutter pub get" 无法获取依赖插件

"flutter pub get" can't get dependency plugins

我一直在尝试为我的 Flutter 项目在 Windows 上获取依赖项,但这需要很长时间,过了一段时间后,它在 'messages' 栏中显示此错误。

Running "flutter pub get" in badhan_blood_bank...               
OS Error: The semaphore timeout period has expired.

, errno = 121, address = storage.googleapis.com, port = 53515

pub get failed (server unavailable) -- attempting retry 1 in 1 second...

我正在尝试通过一些方法解决这个问题,但未能解决。 我正在做 flutter clean、flutter upgrade 并重启 android studio 最后发生同样的问题。

在我将 url_launcher 添加到我的项目的依赖项之前它工作正常。

这是我的 pubspec.yaml 文件:

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  firebase_auth: ^0.15.5+2
  flutter_facebook_login: ^3.0.0
  flutter_icons: ^1.0.0+1
  flutter_spinkit: ^4.1.2
  firebase_database: ^3.1.3
  google_maps_flutter: ^0.5.25
  geolocator: ^5.3.0
  intl: ^0.16.1
  curved_navigation_bar: ^0.3.2
  fluttertoast: ^4.0.1
  url_launcher: ^5.4.2



dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

  assets:
  - images/


运行"flutter pub get --verbose"后显示:

[  +27 ms] executing: [C:\src\flutter\flutter\] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +64 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] 0b8abb4724aa590dd0f429683339b1e045a1594d
[        ] executing: [C:\src\flutter\flutter\] git describe --match v*.*.* --first-parent --long --tags
[  +56 ms] Exit code 0 from: git describe --match v*.*.* --first-parent --long --tags
[        ] v1.12.13+hotfix.8-0-g0b8abb472
[   +7 ms] executing: [C:\src\flutter\flutter\] git rev-parse --abbrev-ref --symbolic @{u}
[  +41 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [C:\src\flutter\flutter\] git ls-remote --get-url origin
[  +38 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +77 ms] executing: [C:\src\flutter\flutter\] git rev-parse --abbrev-ref HEAD
[  +41 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +48 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +4 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +130 ms] Running "flutter pub get" in badhan_blood_bank...
[   +5 ms] Using C:\src\flutter\flutter\.pub-cache for the pub cache.
[   +1 ms] executing: [D:\@@MyWorks\mahmud\Badhan Blood Bank\badhan_blood_bank\] C:\src\flutter\flutter\bin\cache\dart-sdk\bin\pub.bat --verbose get
--no-precompile
[ +157 ms] FINE: Pub 2.7.0
[   +3 ms] IO  : Spawning "cmd /c ver" in D:\@@MyWorks\mahmud\Badhan Blood Bank\badhan_blood_bank\.
[   +7 ms] IO  : Finished ver. Exit code 0.
[   +1 ms]     | stdout:
[        ]     | | 
[   +1 ms]     | | Microsoft Windows [Version 10.0.18362.720]
[   +1 ms]     | Nothing output on stderr.
[ +102 ms] MSG : Resolving dependencies...
[   +9 ms] SLVR: fact: badhanbloodbank is 1.0.0+1
[   +5 ms] SLVR: derived: badhanbloodbank
[  +61 ms] SLVR: fact: badhanbloodbank depends on flutter any from sdk
[   +1 ms] SLVR: fact: badhanbloodbank depends on cupertino_icons ^0.1.2
[   +1 ms] SLVR: fact: badhanbloodbank depends on firebase_auth ^0.15.5+2
[   +1 ms] SLVR: fact: badhanbloodbank depends on flutter_facebook_login ^3.0.0
[   +1 ms] SLVR: fact: badhanbloodbank depends on flutter_icons ^1.0.0+1
[   +1 ms] SLVR: fact: badhanbloodbank depends on flutter_spinkit ^4.1.2
[        ] SLVR: fact: badhanbloodbank depends on firebase_database ^3.1.3
[        ] SLVR: fact: badhanbloodbank depends on google_maps_flutter ^0.5.25
[        ] SLVR: fact: badhanbloodbank depends on geolocator ^5.3.0
[        ] SLVR: fact: badhanbloodbank depends on intl ^0.16.1
[        ] SLVR: fact: badhanbloodbank depends on curved_navigation_bar ^0.3.2
[        ] SLVR: fact: badhanbloodbank depends on fluttertoast ^4.0.1
[        ] SLVR: fact: badhanbloodbank depends on url_launcher ^5.4.2
[        ] SLVR: fact: badhanbloodbank depends on flutter_test any from sdk
[        ] SLVR:   selecting badhanbloodbank
[        ] SLVR:   derived: flutter_test any from sdk
[        ] SLVR:   derived: url_launcher ^5.4.2
[   +1 ms] SLVR:   derived: fluttertoast ^4.0.1
[   +1 ms] SLVR:   derived: curved_navigation_bar ^0.3.2
[        ] SLVR:   derived: intl ^0.16.1
[   +1 ms] SLVR:   derived: geolocator ^5.3.0
[   +1 ms] SLVR:   derived: google_maps_flutter ^0.5.25
[   +1 ms] SLVR:   derived: firebase_database ^3.1.3
[        ] SLVR:   derived: flutter_spinkit ^4.1.2
[        ] SLVR:   derived: flutter_icons ^1.0.0+1
[        ] SLVR:   derived: flutter_facebook_login ^3.0.0
[        ] SLVR:   derived: firebase_auth ^0.15.5+2
[        ] SLVR:   derived: cupertino_icons ^0.1.2
[        ] SLVR:   derived: flutter any from sdk
[        ] IO  : Get versions from https://pub.dartlang.org/api/packages/url_launcher.
[   +9 ms] IO  : HTTP GET https://pub.dartlang.org/api/packages/url_launcher
[   +2 ms]     | Accept: application/vnd.pub.v2+json
[   +1 ms]     | X-Pub-OS: windows
[        ]     | X-Pub-Command: get
[        ]     | X-Pub-Session-ID: 795584D9-523C-4575-B686-2D496C324C5B
[        ]     | X-Pub-Environment: flutter_cli:get
[   +1 ms]     | X-Pub-Reason: direct
[        ]     | user-agent: Dart pub 2.7.0
[ +934 ms] IO  : HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/url_launcher
[   +5 ms]     | took 0:00:00.938247
[   +2 ms]     | transfer-encoding: chunked
[   +2 ms]     | date: Sun, 29 Mar 2020 19:47:07 GMT
[   +2 ms]     | content-encoding: gzip
[   +2 ms]     | vary: Accept-Encoding
[   +3 ms]     | strict-transport-security: max-age=31536000; preload
[   +3 ms]     | via: 1.1 google
[   +2 ms]     | content-type: application/json
[   +2 ms]     | x-frame-options: SAMEORIGIN
[   +2 ms]     | x-xss-protection: 1; mode=block
[   +2 ms]     | x-content-type-options: nosniff
[   +2 ms]     | server: dart:io with Shelf
[  +66 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on flutter any from sdk
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on test_api 0.2.11
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on path 1.6.4
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on image 2.1.4
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on quiver 2.0.5
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on stack_trace 1.9.3
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on vector_math 2.0.8
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on archive 2.0.11
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on args 1.5.2
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on async 2.4.0
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on boolean_selector 1.0.5
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on charcode 1.1.2
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on collection 1.14.11
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on convert 2.1.1
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on crypto 2.1.3
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on matcher 0.12.6
[   +2 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on meta 1.1.8
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on pedantic 1.8.0+1
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on petitparser 2.4.0
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on source_span 1.5.5
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on stream_channel 2.0.0
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on string_scanner 1.0.5
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on term_glyph 1.1.0
[        ] SLVR:   fact: flutter_test 0.0.0 from sdk depends on typed_data 1.1.6
[   +1 ms] SLVR:   fact: flutter_test 0.0.0 from sdk depends on xml 3.5.0
[        ] SLVR:     selecting flutter_test 0.0.0 from sdk
[        ] SLVR:     derived: xml 3.5.0
[        ] SLVR:     derived: typed_data 1.1.6
[   +1 ms] SLVR:     derived: term_glyph 1.1.0
[        ] SLVR:     derived: string_scanner 1.0.5
[        ] SLVR:     derived: stream_channel 2.0.0
[   +2 ms] SLVR:     derived: source_span 1.5.5
[        ] SLVR:     derived: petitparser 2.4.0
[        ] SLVR:     derived: pedantic 1.8.0+1
[        ] SLVR:     derived: meta 1.1.8
[   +3 ms] SLVR:     derived: matcher 0.12.6
[        ] SLVR:     derived: crypto 2.1.3
[        ] SLVR:     derived: convert 2.1.1
[   +1 ms] SLVR:     derived: collection 1.14.11
[        ] SLVR:     derived: charcode 1.1.2
[        ] SLVR:     derived: boolean_selector 1.0.5
[        ] SLVR:     derived: async 2.4.0
[   +1 ms] SLVR:     derived: args 1.5.2
[   +4 ms] SLVR:     derived: archive 2.0.11
[   +1 ms] SLVR:     derived: vector_math 2.0.8
[   +4 ms] SLVR:     derived: stack_trace 1.9.3
[   +1 ms] SLVR:     derived: quiver 2.0.5
[        ] SLVR:     derived: image 2.1.4
[   +1 ms] SLVR:     derived: path 1.6.4
[   +1 ms] SLVR:     derived: test_api 0.2.11
[   +1 ms] SLVR:     fact: url_launcher >=3.0.0 depends on flutter any from sdk
[        ] SLVR:     fact: url_launcher >=5.4.0 depends on url_launcher_macos ^0.0.1
[   +1 ms] SLVR:     fact: url_launcher >=5.4.1 depends on url_launcher_platform_interface ^1.0.4
[   +1 ms] SLVR:     fact: url_launcher >=5.3.0 depends on url_launcher_web ^0.1.0+1
[   +1 ms] SLVR:       selecting url_launcher 5.4.2
[        ] SLVR:       derived: url_launcher_web ^0.1.0+1
[        ] SLVR:       derived: url_launcher_platform_interface ^1.0.4
[        ] SLVR:       derived: url_launcher_macos ^0.0.1
[   +1 ms] IO  : Get versions from https://pub.dartlang.org/api/packages/url_launcher_web.
[   +1 ms] IO  : HTTP GET https://pub.dartlang.org/api/packages/url_launcher_web
[        ]     | Accept: application/vnd.pub.v2+json
[        ]     | X-Pub-OS: windows
[        ]     | X-Pub-Command: get
[        ]     | X-Pub-Session-ID: 795584D9-523C-4575-B686-2D496C324C5B
[        ]     | X-Pub-Environment: flutter_cli:get
[        ]     | user-agent: Dart pub 2.7.0
[ +429 ms] IO  : HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/url_launcher_web

问题是什么,如何解决?

从昨天开始,storage.googleapis.com 在孟加拉国出现了一些问题。

首先,我认为这可能是 Google 的基础设施的问题。
但是,一段时间后我意识到这是 BTCL 的问题。

要解决此问题,您可以使用 VPN 工具并重新 运行 您的项目。
我用了 Hotspot Sheild VPN 之后一切都很好。

请记住,免费版本限制为 500 MB/Day

我希望这对你也有用。

  1. 更新 Flutter 将不起作用
  2. 重启电脑无效
  3. 创建新项目和运行pub get 将不起作用。

如果你来自孟加拉国,那么暂时只能使用VPN。导致此问题的 BTCL 存在一些网络问题。

'flutter pub get' 尝试获取您在 pubspec.yaml 中声明的插件,默认情况下它会向 pub.dev 或 https://pub.dartlang.org. So if either https://pub.dartlang.org 或 [=44 发出 GET 请求=] 被您的 isp 或您公司的防火墙阻止,您将无法完成包获取,因此无法构建您的 flutter 项目。 与其使用 vpn,我更喜欢使用镜像存储库。您可以简单地使用镜像 link 更改或设置两个环境变量,如下所述。之后 'flutter pub get' 命令将尝试从特定镜像 link 获取您的包。变量和 links 是 - * PUB_HOSTED_URL=https://pub.flutter-io.cn * FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

对于windows,在cmd中使用这些命令来设置项目环境中的变量:

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

确保在 cmd 中的项目目录中应用这些命令,并使用该特定 cmd 中的 'flutter pub get'。 您可以通过应用检查变量是否已设置:

echo %PUB_HOSTED_URL% 

输出应该是你刚刚设置的URL。

这些变量仅为该环境设置,当您关闭该终端时将被清除。所以对于 windows,如果你在你的系统用户环境中设置这些变量,那么你将能够使用 'flutter pub get' 并随时从 china 镜像站点获取包。

对于 mac,像这样导出 bash_profile 中的变量:

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

之后你应该可以成功申请flutter pub get了。 (记得在设置变量后获取 bash_profile)

经过这一切,如果您仍然无法获取包裹: * 从项目中删除 pubspec.lock 文件。 * 重新启动您的电脑。 * 使用 echo 命令检查 PUB_HOSTED_URL & FLUTTER_STORAGE_BASE_URL 环境变量是否设置正确。

如果设置了这些变量,flutter sdk 将尝试从您通过该变量设置的镜像站点获取包。如果工作区环境中不存在这些变量,则 flutter sdk 将尝试使用前面提到的默认 url 来获取包。

N.B:当它对我不起作用时,我很沮丧并重新安装了 flutter sdk,然后在我的环境中设置了这些变量并从项目中删除了 pubspec.lock 文件。还有尤里卡!!它对我有用。在那之后,通过一些挖掘,我发现我不必再次卸载和安装 flutter。

希望您现在能够在没有 vpn 和其他任何东西的情况下获得包裹。 祝你好运。

只需关闭 IDE 中的项目并重新打开它。然后 运行 pub get.