- 安装独立的
dart
环境
官方安装方法:https://dart.dev/get-dart
或者下载包:https://dart.dev/tools/sdk/archive
brew tap dart-lang/dart
brew install dart
- 更新
dart
版本:
brew upgrade dart
- 重新安装
dart
:
brew reinstall dart
- 查看当前dart版本:
$ dart --version
Dart SDK version: 2.13.1 (stable) (Fri May 21 12:45:36 2021 +0200) on "macos_x64"
- 查看当前安装的dart信息:
$ brew info dart
dart-lang/dart/dart: stable 2.13.1, HEAD
The Dart SDK
https://dart.dev
Conflicts with:
dart-beta (because dart-beta ships the same binaries)
/usr/local/Cellar/dart/2.13.1 (508 files, 477.8MB) *
Built from source on 2021-05-31 at 09:44:27
From: https://github.com/dart-lang/homebrew-dart/blob/HEAD/dart.rb
==> Options
--HEAD
Install HEAD version
==> Caveats
Please note the path to the Dart SDK:
/usr/local/opt/dart/libexec
- 安装
fvm
命令:pub global activate fvm
$ pub global activate fvm
Package fvm is currently active at version 2.0.5.
Resolving dependencies... (3.4s)
The package fvm is already activated at newest available version.
To recompile executables, first run `global decativate fvm`.
Installed executable fvm.
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Activated fvm 2.0.5.
- 配置
.bash_profile
中添加:
# fvm
export PATH="$PATH":"$HOME/.pub-cache/bin"
使.bash_profile
生效:
source ~/.bash_profile
重启命令行工具,执行fvm
:
$ fvm
Flutter Version Management: A cli to manage Flutter SDK versions.
Usage: fvm [arguments]
Global options:
-h, --help Print this usage information.
--verbose Print verbose output.
--version current version
Available commands:
config Set configuration for FVM
dart Proxies Dart Commands
doctor Shows information about environment, and project configuration.
flavor Switches between different project flavors
flutter Proxies Flutter Commands
global Sets Flutter SDK Version as a global
install Installs Flutter SDK Version
list Lists installed Flutter SDK Versions
releases View all Flutter SDK releases available for install.
remove Removes Flutter SDK Version
spawn Spawns a command on a Flutter version
use Sets Flutter SDK Version you would like to use in a project
Run "fvm help " for more information about a command.
-
fvm
相关命令
fvm官方使用文档
- 配置
fvm
缓存路径(可选,默认在用户目录下fvm/versions
文件夹):
fvm config --cache-path
- 查看当前安装的flutter版本:
$ fvm list
No SDKs have been installed yet. Flutter. SDKs installed outside of fvm
will not be displayed.
- 安装指定版本的flutter:
$ fvm install 2.2.1
Flutter "2.2.1" is not installed.
Installing version: 2.2.1...
Cloning into '/Users/yuanzhiying/fvm/versions/2.2.1'...
- 删除指定版本:
$ fvm remove 2.2.0
Removing 2.2.0...
2.2.0 removed.
此时会在用户目录下自动创建fvm/versions/2.2.1
文件夹,如果本地已有flutter
,可将本地的flutter
拷贝到versions
目录下,文件夹改为对应的版本名。当前flutter
版本可以在flutter
根目录下的version
文件里查看。
/Users/yuanzhiying/fvm/versions/1.22.6
- 查看已安装的flutter版本:
$ fvm list
Cache Directory: /Users/yuanzhiying/fvm/versions
2.2.0
1.22.6
- 查看环境信息和项目配置
FVM Version: 2.0.5
___________________________________________________
FVM config found:
___________________________________________________
Project: info_valley
Directory: /Users/yuanzhiying/mobile_life/info_valley
Version: 1.22.6
Project Flavor: None selected
___________________________________________________
Version is currently cached locally.
Cache Path: /Users/yuanzhiying/fvm/versions/1.22.6
Channel: false
SDK Version: 1.22.6
IDE Links
VSCode: .fvm/flutter_sdk
Android Studio: /Users/yuanzhiying/mobile_life/info_valley/.fvm/flutter_sdk
Configured env paths:
___________________________________________________
Flutter:
Dart:
/usr/local/Cellar/dart/2.13.1/libexec/bin/dart
FVM_HOME:
not set
- 使用对应版本的flutter:
切换至项目目录,执行命令:
$ cd mobile_life/info_valley
$ fvm use 1.22.6
Project now uses Flutter [1.22.6]
HandshakeException: Connection terminated during handshake
查看当前的使用版本:
$ fvm list
Cache Directory: /Users/yuanzhiying/fvm/versions
2.2.0
1.22.6 (active)
项目目录下会生成一个隐藏文件夹.fvm
- 配置项目忽略文件.gitignore
.fvm/flutter_sdk
- 项目配置
flutter
路径
选择flutter
的sdk
路径:
自动生成当前使用的flutter
路径:
重启Android studio。
-
flutter
命令的使用
此时执行flutter doctor
找不到flutter
命令:
$ flutter doctor
zsh: command not found: flutter
所有flutter
命令前加上fvm
即可:
$ fvm flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.3 20E232 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.5)
[✓] Android Studio (version 4.2)
[!] Connected device
! Error: 营的iPhone is not connected. Xcode will continue when 营的iPhone is connected. (code -13)
! Doctor found issues in 1 category.
$ fvm flutter pub get
Running "flutter pub get" in info_valley... 1.4s
-
flutter
下dart
命令的使用
所有dart
命令前加上fvm
即可:
$ fvm dart --version
fvm: running Dart from Flutter "1.22.6"
Dart SDK version: 2.10.5 (stable) (Tue Jan 19 13:05:37 2021 +0100) on "macos_x64"
- 便捷使用命令
在.bash_profile
中设置命令的别名:
# aliases 快捷使用fvm命令
alias flutter="fvm flutter"
alias dart="fvm dart"
使生效:
source ~/.bash_profile
重启命令行工具。
$ flutter pub get
Running "flutter pub get" in info_valley... 1.0s
$ dart --version
Running using Flutter version configured in path.
Dart SDK version: 2.13.1 (stable) (Fri May 21 12:45:36 2021 +0200) on "macos_x64"
- 设置全局默认的flutter版本
$ fvm global 1.22.6
Flutter "1.22.6" has been set as global
However your "flutter" path current points to:
.
to use global Flutter SDK through FVM you should change it to:
/Users/yuanzhiying/fvm/default/bin
此时fvm
目录下自动生成了一个default
的快捷文件夹。