2021/01時点 flutter freezed の build が無限に終わらない時のたったひとつのcoolな解決法

2 min読了の目安(約2100字TECH技術記事

TL;DR

  • pubspec.yaml の dependenciesanalyzer を追加して再ビルドすればOK

症状:ちょっと古いプロジェクトの freezed build が無限に終わらない

flutter packages pub run build_runner build --delete-conflicting-outputs

したときに、

[INFO] 17.7s elapsed, 1/9 actions completed.
[INFO] 18.8s elapsed, 1/9 actions completed.
[INFO] 19.9s elapsed, 1/9 actions completed.
[INFO] 20.9s elapsed, 1/9 actions completed.
[INFO] 22.0s elapsed, 1/9 actions completed.
[INFO] 23.0s elapsed, 1/9 actions completed.
...

と出力が出続けて無限に終わらない状況になることがある(なった)

原因:たぶんこれ……かな……?

https://twitter.com/_mono/status/1317015595594862593?s=20

※monoさんいつもありがとうございます

解決法:dependenciesanalyzer を追加して再ビルド

pubspec.yaml
dependencies:
  analyzer: ^0.39.14  # <- 追記

これでもいけるらしい

pubspec.yaml
dependency_overrides:
  analyzer: ^0.39.14  # <- 追記

綺麗にしてから再ビルド。

rm -rf pubspec.lock
flutter clean
flutter pub get
flutter packages pub run build_runner build --delete-conflicting-outputs

いけた!

[INFO] 6.4s elapsed, 0/9 actions completed.
[INFO] 7.5s elapsed, 0/9 actions completed.
[INFO] 8.5s elapsed, 0/9 actions completed.
[INFO] 9.8s elapsed, 0/9 actions completed.
[INFO] 10.8s elapsed, 0/9 actions completed.
[INFO] 12.3s elapsed, 1/9 actions completed.
[INFO] 13.4s elapsed, 1/9 actions completed.
[INFO] 15.8s elapsed, 1/9 actions completed.
[INFO] 16.8s elapsed, 2/9 actions completed.
[INFO] 19.7s elapsed, 4/9 actions completed.
[INFO] 21.9s elapsed, 5/9 actions completed.
[INFO] 22.9s elapsed, 23/31 actions completed.
[INFO] Running build completed, took 23.1s

参考