【Flutter】flutter downgradeが出来ない

2024/03/12に公開

初めに

当時の最新版の環境(Flutter 3.13.4)で上手く行かないプロジェクトがあり、Flutter SDKのバージョンを下げることにしたのでその備忘録です。

=======環境========
MacBook Pro 14インチ、2021
チップ:Apple M1 Pro
メモリ:16GB
macOS:14.3.1
=================

% flutter --version
Flutter 3.13.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 367f9ea16b (6 months ago) • 2023-09-12 23:27:53 -0500
Engine • revision 9064459a8b
Tools • Dart 3.1.2 • DevTools 2.25.0

flutter downgrade

$ flutter downgrade 2.2.3
Checking Dart SDK version...
Downloading Dart SDK from Flutter engine b09f014e9658da6647361e7e416d1a159d34192d...
Building flutter tool...
Running pub upgrade...
Downloading Material fonts...                                    1,194ms
Downloading Gradle Wrapper...                                       43ms
Downloading package sky_engine...                                  462ms
Downloading flutter_patched_sdk tools...                            5.0s
Downloading flutter_patched_sdk_product tools...                    4.9s
Downloading windows-x64 tools...                                   11.0s
Downloading windows-x64/font-subset tools...                     1,106ms
There is no previously recorded version for channel "stable".
C:\flutter>

エラーとなってしまったので、Googleで捜索してみると、SDKのディレクトリでGitから取得するとよいとの情報がありました。

または、flutter downgrade [バージョン]
とやっているのに、逆に最新版を入れようとしてくることもありました。

Git

以下のように、バージョンを下げました。

$ pwd
/Users/ユーザー名/Development/flutter ←flutter SDKのインストールディレクトリ
$ git fetch
remote: Enumerating objects: 130, done.
remote: Counting objects: 100% (122/122), done.
remote: Total 130 (delta 121), reused 121 (delta 121), pack-reused 8
Receiving objects: 100% (130/130), 179.82 KiB | 19.98 MiB/s, done.
Resolving deltas: 100% (121/121), completed with 70 local objects.
From https://github.com/flutter/flutter
   ff59250dbe..2703a2bcde  main       -> origin/main
   ff59250dbe..2703a2bcde  master     -> origin/master
 * [new branch]            revert-115009-fix_linux_remapped_capslock_throws -> origin/revert-115009-fix_linux_remapped_capslock_throws
$ git tag
0.0.10
0.0.11
0.0.12
0.0.13
0.0.14
0.0.15
〜〜〜〜省略〜〜〜〜〜〜 〜
3.9.0-19.0.pre
3.9.0-20.0.pre
3.9.0-21.0.pre
3.9.0-6.0.pre
3.9.0-7.0.pre
3.9.0-8.0.pre
3.9.0-9.0.pre
$ git checkout 2.2.3 ← 戻したいバージョンを指定してチェックアウト
Updating files: 100% (3492/3492), done.
Note: switching to '2.2.3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 7e9793dee1 [flutter_releases] Flutter stable 2.10.3 Framework Cherrypicks (#99337)
$ flutter --version
Downloading Dart SDK from Flutter engine bd539267b42051b0da3d16ffa8f48949dce8aa8f...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  209M  100  209M    0     0  2172k      0  0:01:38  0:01:38 --:--:-- 2404k
Building flutter tool...
Flutter 2.2.3 • channel unknown • unknown source
Framework • revision f4abaa0735 (2 years, 8 months ago) • 2021-07-01 12:46:11 -0700
Engine • revision 241c87ad80
Tools • Dart 2.13.4

確認

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 2.2.3, on macOS 13.0.1 22A400 darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
[✓] VS Code (version 1.73.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

無事にダウングレードすることができました。
Gitからチェックアウトするのがよいとのことです。

参考

https://qiita.com/mighty-n/items/5bdb37cce7c7541905ce
https://qiita.com/tec9w0rks/items/33b0b061142887d956d1

Discussion