【Flutter】プロキシ環境でデバッグ実行ができない【Windows】

flutter

Windows のプロキシ環境で Flutter アプリのデバッグ実行ができない問題が発生したので紹介します。
動作確認環境:Windows 10
実行環境: VSCode

エラー内容

Chrome や Windows に関係なく実行できませんでした。
通常の実行だと実行ができるのでデバッグのみの問題だと考えています。

コンソールには以下のようなメッセージが出力されていました。

Launching lib\main.dart on Windows in debug mode...

main.dart:1

Connecting to the VM Service is taking longer than expected...

Still attempting to connect to the VM Service...

If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.

If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.

Exception attempting to connect to the VM Service: WebSocketException: Connection to 'http://127.0.0.1:52118/AyWyAzfIv9I=/ws#' was not upgraded to websocket

This was attempt #50. Will retry in 0:00:01.600000.

原因と解決策

色々と調べたり設定を変えて試したところ、今回はプロキシが原因ということがわかりました。

Flutter の言語である Dart は 環境変数のプロキシ設定を参照しますが、どうも「no_proxy」の設定がうまく参照されていなかったようです。

Windows の環境変数のため区切り文字を「;(セミコロン)」にしていましたが、Dart は「,(カンマ)」じゃないと区切り文字として認識してくれないようです。
https://github.com/flutter/flutter/issues/62341

区切り文字を「,」に変換して実行したら正常に実行できました。

ただし、そのせいで git のコマンドが実行できなくなりました。。。
両立させる方法はまだ見つかっていません。
とりあえずバッチを作って切り替えていますが、そのたびに再起動しないと行けないのが辛いです。
はやく解決策を見つけたいです。

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