Flutterのバージョン管理にFVMを使う

プログラム(プロジェクト)が多くなってくると、それぞれのプロジェクトでFlutterのバージョンを固定・指定したくなってきます。
FVMを使うとプロジェクトディレクトリごとにFlutterのバージョンを指定できるようです。
また、プロジェクト内にfvmの設定を含めておくと、各個人の環境でそのバージョンのFlutterをインストールできるようになります。
便利ですねー。

FVMのインストール

こちらの公式サイトを参考にインストールしましょう。

Macでのインストール方法はこちら。

brew tap leoafarias/fvm
brew install fvm

Flutterのインストール

リリースされているバージョン一覧で確認する。

% fvm releases
:
:
Jun 7 23   │ 3.10.4           
Jun 8 23   │ 3.12.0           
Jun 14 23  │ 3.10.5           
Jun 21 23  │ 3.12.0-1.1.pre   
Jul 12 23  │ 3.13.0-0.1.pre   
--------------------------------------
Jul 12 23  │ 3.10.6            stable
--------------------------------------
Jul 19 23  │ 3.13.0-0.2.pre   
Aug 7 23   │ 3.13.0-0.3.pre   
--------------------------------------
Aug 14 23  │ 3.13.0-0.4.pre    beta
--------------------------------------

使用したいバージョンをインストールする。

% fvm install 3.10.6
==========
Flutter "3.10.6" is not installed.

Installing version: 3.10.6...
Cloning into '/Users/username/fvm/versions/3.10.6'...
remote: Enumerating objects: 463743, done.        
remote: Counting objects: 100% (463741/463741), done.        
remote: Compressing objects: 100% (88901/88901), done.        
remote: Total 463743 (delta 356733), reused 462896 (delta 356241), pack-reused 2        
Receiving objects: 100% (463743/463743), 258.29 MiB | 8.56 MiB/s, done.
Resolving deltas: 100% (356733/356733), done.
HEAD is now at f468f3366c [flutter_releases] Flutter stable 3.10.6 Framework Cherrypicks (#130446)
Downloading Darwin arm64 Dart SDK from Flutter engine cdbeda788a293fa29665dc3fa3d6e63bd221cb0d...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  187M  100  187M    0     0  8288k      0  0:00:23  0:00:23 --:--:-- 8540k
Building flutter tool...
Resolving dependencies...
Got dependencies.
Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (5 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

Flutterのプロジェクト作成

プロジェクトのディレクトリを作成する

% mkdir sample-app

ディレクトリにFlutterの利用バージョンを指定する

% cd sample-app
% fvm use 3.10.6 --force
Project now uses Flutter [3.10.6]

.fvmディレクトリが作成されてflutter_sdkへのリンクとバージョン情報の設定ファイルが作成されるようです。

% ls -la
total 0
drwxr-xr-x  3 username  staff   96  8 16 22:35 .
drwxr-xr-x  8 username  staff  256  8 16 22:21 ..
drwxr-xr-x  4 username  staff  128  8 16 22:35 .fvm
% ls -la .fvm
total 8
drwxr-xr-x  4 username  staff  128  8 16 22:35 .
drwxr-xr-x  3 username  staff   96  8 16 22:35 ..
lrwxr-xr-x  1 username  staff   34  8 16 22:35 flutter_sdk -> /Users/username/fvm/versions/3.10.6
-rw-r--r--  1 username  staff   52  8 16 22:35 fvm_config.json
% cat .fvm/fvm_config.json 
{
  "flutterSdkVersion": "3.10.6",
  "flavors": {}
}

Flutterプロジェクト作成

% fvm flutter create . --project-name sample_app --platforms android,ios --org com.sampleapp -e
==========
Downloading Material fonts...                                      414ms
Downloading Gradle Wrapper...                                       18ms
Downloading package sky_engine...                                  123ms
Downloading flutter_patched_sdk tools...                           343ms
Downloading flutter_patched_sdk_product tools...                   385ms
Downloading darwin-arm64 tools...                                   3.8s
Downloading libimobiledevice...                                     24ms
Downloading usbmuxd...                                              16ms
Downloading libplist...                                             15ms
Downloading openssl...                                             207ms
Downloading ios-deploy...                                           25ms
Downloading darwin-arm64/font-subset tools...                      169ms
Recreating project ....
  pubspec.yaml (created)
  README.md (created)
  lib/main.dart (created)
  test/widget_test.dart (created)
  ios/Runner.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (created)
  ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (created)
  ios/Runner/Info.plist (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png (created)
  ios/Runner/Base.lproj/LaunchScreen.storyboard (created)
  ios/Runner/Base.lproj/Main.storyboard (created)
  ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (created)
  ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (created)
  ios/Flutter/Debug.xcconfig (created)
  ios/Flutter/Release.xcconfig (created)
  ios/Flutter/AppFrameworkInfo.plist (created)
  ios/.gitignore (created)
  sample_app.iml (created)
  .gitignore (created)
  android/app/src/profile/AndroidManifest.xml (created)
  android/app/src/main/res/mipmap-mdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-hdpi/ic_launcher.png (created)
  android/app/src/main/res/drawable/launch_background.xml (created)
  android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (created)
  android/app/src/main/res/values-night/styles.xml (created)
  android/app/src/main/res/values/styles.xml (created)
  android/app/src/main/res/drawable-v21/launch_background.xml (created)
  android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (created)
  android/app/src/main/AndroidManifest.xml (created)
  android/app/src/debug/AndroidManifest.xml (created)
  android/gradle/wrapper/gradle-wrapper.properties (created)
  android/gradle.properties (created)
  android/.gitignore (created)
  android/settings.gradle (created)
  android/app/build.gradle (created)
  android/app/src/main/kotlin/com/sampleapp/sample_app/MainActivity.kt (created)
  android/build.gradle (created)
  android/sample_app_android.iml (created)
  ios/RunnerTests/RunnerTests.swift (created)
  ios/Runner/Runner-Bridging-Header.h (created)
  ios/Runner/AppDelegate.swift (created)
  ios/Runner.xcodeproj/project.pbxproj (created)
  ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (created)
  analysis_options.yaml (created)
  .idea/runConfigurations/main_dart.xml (created)
  .idea/libraries/Dart_SDK.xml (created)
  .idea/libraries/KotlinJavaRuntime.xml (created)
  .idea/modules.xml (created)
  .idea/workspace.xml (created)
Resolving dependencies...
Got dependencies.
Wrote 73 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your empty application, type:

  $ cd .
  $ flutter run

Your empty application code is in ./lib/main.dart.

パラメータの説明

  • リポジトリ名の区切りをハイフンにしたいので、ディレクトリ名もハイフンにする
  • fvm flutter create .
    ディレクトリ名を指定するが、ディレクトリ内で実行するのでカレントディレクトリを指定する
  • –project-name sample_app
    パッケージ名にハイフンを利用できないため、アンダーバー区切りで指定する
  • –org com.sampleapp
    任意のドメイン名を指定する
  • -e
    デフォルトで作られるSample実装や大量のコメントが作成されなくなる

コメント