Flutter pub get错误

Flutter pub get 提示错误:

在Flutter项目中,通过flutter cache clean删除了依赖缓存,再运行flutter pub get或flutter doctor后提示错误,多方查找原因,发现了可以解决的办法,在这里记录一下。


错误提示

>flutter pub get
Pub failed to rename directory because access was denied.
This may be caused by a virus scanner or having a file
in the directory open in another application.
Running "flutter pub get" in flutter_tools...
pub get failed (1; in the directory open in another application.)

原因分析:

  1. 没有文件权限

    虽然我把flutter SDK放到了C盘,还是会出现这样的报错。

  2. 环境变量配置
    PUB_HOSTED_URL=https://pub.flutter-io.cn FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn


解决方案:

  1. 删除 .pub-cache 文件夹下的所有文件。
  2. https://github.com/flutter/flutter/issues/40331
  3. https://github.com/dart-lang/pub/issues/1798

希望以上解决方案可以给你帮助。

你可能感兴趣的:(flutter,flutter,android,android,studio)