官术网_书友最值得收藏!

Solving problems when pub get fails

The pub package manager is a complex tool with many functionalities, so it is not surprising that occasionally something goes wrong. The pub get command downloads all the libraries needed by your app, as specified in the pubspec.yaml file. Running pub get behind a proxy or firewall used to be a problem, but it was solved in the majority of cases. If this still haunts you, look at the corresponding section at https://www.dartlang.org/tools/editor/troubleshoot.html.

Getting ready

This recipe is especially useful when you encounter the following error in your Dart console while trying to open a project in Dart Editor during the pub get phase:

Pub install fails with 'Deletion failed'

How to do it...

First try this; right-click on your project and select Close Folder. Then, restart the editor and open your project again. In many cases, your project will load fine. If this does not work, try the pub gun command:

  1. Delete the pub cache folder from C:\Users\{your username}\AppData\Roaming\Pub.
  2. Delete all the packages folders in your project (also in subfolders).
  3. Delete the pubspec.lock file in your project.
  4. Run pub get again from a command line or select Tools in the Dart Editor menu, and then select Pub Get.

How it works...

The Pub\Cache subfolder contains all the packages that have been downloaded in your Dart environment. Your project contains symlinks to the projects in this cache, which sometimes go wrong, mostly on Windows. The pubspeck.lock file keeps the downloaded projects constrained to certain versions; removing this constraint can also be helpful.

There's more...

Temporarily disabling the virus checker on your system can also help pub get to succeed when it fails with the virus checker on.

The following script by Richard Schmidt that downloads packages from the pub repository and unpacks it into your Dart cache may also prove to be helpful for this error, which can be found at https://github.com/hangstrap/downloadFromPub. Use it as dart downloadFromPub.dart package m.n.l.

Here, package is the package you want to install and m.n.l is the version number such as 0.8.1. You will need to build this like any other dart package, and if during this process the pub get command fails, you will have to download the package and unpack it manually; however, from then on, you should be able to use this script to work around this issue.

When pub get fails in Dart Editor, try the following on the command line to get more information on the possible reasons for the pub --trace 'upgrade' failure.

There is now also a way to condense these four steps into one command in a terminal as follows:

pub cache repair
主站蜘蛛池模板: 松江区| 岳普湖县| 太仓市| 儋州市| 桐柏县| 长治县| 灵山县| 壶关县| 晋江市| 昭觉县| 黄大仙区| 无棣县| 那曲县| 佛教| 宁远县| 泌阳县| 宁陵县| 锡林郭勒盟| 扶风县| 连城县| 定边县| 宝坻区| 鄂尔多斯市| 垫江县| 云和县| 长丰县| 泾川县| 长丰县| 武乡县| 楚雄市| 武威市| 阿坝| 邓州市| 徐汇区| 开远市| 钦州市| 饶阳县| 甘德县| 阳原县| 青海省| 什邡市|