MacOS使用fvm管理多個flutter版本

  1. 安裝獨立的dart環(huán)境

官方安裝方法: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
  1. 安裝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.
  1. 配置

.bash_profile中添加:

# fvm
export PATH="$PATH":"$HOME/.pub-cache/bin"

使.bash_profile生效:

source ~/.bash_profile

重啟命令行工具骗村,執(zhí)行fvm

$ fvm
Flutter Version Management: A cli to manage Flutter SDK versions.

Usage: fvm <command> [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 <command>" for more information about a command.
  1. fvm相關(guān)命令

fvm官方使用文檔

  • 配置fvm緩存路徑(可選撵儿,默認在用戶目錄下fvm/versions文件夾):
fvm config --cache-path <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.

此時會在用戶目錄下自動創(chuàng)建fvm/versions/2.2.1文件夾弯菊,如果本地已有flutter巷疼,可將本地的flutter拷貝到versions目錄下咕娄,文件夾改為對應(yīng)的版本名灾杰。當前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
  • 查看環(huán)境信息和項目配置

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
  1. 使用對應(yīng)版本的flutter:
    切換至項目目錄厂捞,執(zhí)行命令:
$ 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

image.png

  1. 配置項目忽略文件.gitignore
.fvm/flutter_sdk
  1. 項目配置flutter路徑

選擇fluttersdk路徑:

image.png

自動生成當前使用的flutter路徑:

image.png

image.png

重啟Android studio餐屎。

  1. flutter命令的使用

此時執(zhí)行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
  1. flutterdart命令的使用

所有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"
  1. 便捷使用命令

.bash_profile中設(shè)置命令的別名:

# 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"
  1. 設(shè)置全局默認的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的快捷文件夾。

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末腹缩,一起剝皮案震驚了整個濱河市屿聋,隨后出現(xiàn)的幾起案子空扎,更是在濱河造成了極大的恐慌,老刑警劉巖润讥,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件转锈,死亡現(xiàn)場離奇詭異,居然都是意外死亡楚殿,警方通過查閱死者的電腦和手機撮慨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來脆粥,“玉大人砌溺,你說我怎么就攤上這事”涓簦” “怎么了规伐?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長弟胀。 經(jīng)常有香客問我楷力,道長喊式,這世上最難降的妖魔是什么孵户? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮岔留,結(jié)果婚禮上夏哭,老公的妹妹穿的比我還像新娘。我一直安慰自己献联,他們只是感情好竖配,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著里逆,像睡著了一般进胯。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上原押,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天胁镐,我揣著相機與錄音,去河邊找鬼诸衔。 笑死盯漂,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的笨农。 我是一名探鬼主播就缆,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼谒亦!你這毒婦竟也來了竭宰?” 一聲冷哼從身側(cè)響起空郊,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎切揭,沒想到半個月后渣淳,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡伴箩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年入愧,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片嗤谚。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡棺蛛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出巩步,到底是詐尸還是另有隱情旁赊,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布椅野,位于F島的核電站终畅,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏竟闪。R本人自食惡果不足惜离福,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望炼蛤。 院中可真熱鬧妖爷,春花似錦、人聲如沸理朋。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嗽上。三九已至次舌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間兽愤,已是汗流浹背彼念。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留烹看,地道東北人国拇。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像惯殊,于是被迫代替她去往敵國和親酱吝。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容