Flutterのビルドエラーの原因がVisual Studioだった話

Flutter

WindowsでFlutter開発を始めようとFlutterをインストールしたが、Windows(desktop)のみビルドが通らない状況に陥った。

ビルドコマンドの次を実行すると…

flutter run -d windows -v

次のような無骨すぎるエラーが発生…

Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
Error launching application on Windows.

GitHubのFlutterレポジトリでエラーを検索してみても原因がわからなかった。

とりあえず数ヶ月前にインストールしたVisual Studio 2019がちょっとだけ古かったので更新をしてみた。

更新前: Visual Studio 2019 version 16.11.11
更新後: Visual Studio 2019 version 16.11.14

更新後に再度Flutterのプロジェクトをビルドすると次のエラーが

Exception: Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string

このエラーはVisual Studioの更新が原因でビルドに失敗してしまう問題でした。

[windows] Exception: Bad UTF-8 encoding when running flutter doctor or building/running for Windows · Issue #102451 · flutter/flutter
StepstoReproduceSetyourwindowslocaletogermanInstalltheVisualStudio2022BuildToolsInstallthelatestflutterbeta(beta,2.13.0-0.2.pre)Runflutterdoctor>Temporarysoluti...

「vswhere.exe」のUnicode処理に問題があり、バージョン「3.0.2」で修正されていますので、それ以降のバージョンをダウンロードします。

Releases · microsoft/vswhere
LocateVisualStudio2017andnewerinstallations.Contributetomicrosoft/vswheredevelopmentbycreatinganaccountonGitHub.

ダウンロード後に「C:\Program Files (x86)\Microsoft Visual Studio\Installer」にある「vswhere.exe」をダウンロードしたものと置き換えると本件問題が解決するはずです。

vswhere.exeはVisual Studioがどこにインストールされているか、どんなバージョンがインストールされているかを簡単に知ることができる単一のツールです。


今回は2つの問題が重なりビルドに成功するまで時間が掛かりました。

  1. Visual Studio 2019 version 16.11.11ではWindowsデバイス向けのビルドが失敗する(原因不明)
  2. Visual Studio 2019 version 16.11.14では「vswhere.exe」の不良でビルドに失敗

今回インストールしたVisual Studioはどちらも地雷で期待通り動きませんでした。

FlutterをWindows向けにビルドする際にエラーが発生したときはVisual Studio側の問題を疑ってみてください。

コメント

タイトルとURLをコピーしました