chakokuのブログ(rev4)

テック・コミック・DTM・・・ごくまれにチャリ

Flutterでビルド、Launchでエラー・解消・エラー、最後は動く

Flutter Cookbookのサンプル(一番簡単なStaticAppから)を打ち込みながら勉強を開始。。
flutter runでエラーが発生(手元のiPhone実機上では動作してるけど)

% flutter run
Multiple devices found:
sdk gphone64 arm64 (mobile) • emulator-5554                            • android-arm64  • Android 12 (API 32) (emulator)
ipodune (mobile)            • 467171fcxxxxxxxxxxxxxx3434e • ios            • iOS 15.3.1 19D52
Chrome (web)                • chrome                                   • web-javascript • Google Chrome 98.0.4758.102
[1]: sdk gphone64 arm64 (emulator-5554)
[2]: ipodune (46717xxxxxxxxxxxxxxxxxx434e)
[3]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 2
Launching lib/main.dart on ipodune in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: JWxxxxxxxS9
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         8.3s
Xcode build done.                                           35.2s
(lldb) 2022-02-20 17:20:34.365920+0900 Runner[898:46903] Warning: Unable to create restoration in progress marker file
Installing and launching...                                        23.3s
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
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: SocketException: Connection refused (OS Error: Connection refused, errno = 61), address =
127.0.0.1, port = 56532
This was attempt #50. Will retry in 0:00:01.600000.

Macの画面には開発元が信用できずといったメッセージが出たので、認証関係で実行が止められていると思われる。メッセージでは、ポート番号:56532に接続しようとして失敗している?

画面には、

“iproxy”は、開発元を検証できないため開けません。

といった内容のダイアログが出ている。iproxyをどうにかして認証しないと怒られ続けると思われる。
先人の記事より、「セキュリティーとプライバシー」で許可することで回避できるらしい(参考URLご参照のこと)
対策手順で実行許可にしたら、エラーなく実行された。以下がメッセージ、HotRunしたかったらRを押せと。。

 % flutter run
Multiple devices found:
sdk gphone64 arm64 (mobile) • emulator-5554                            • android-arm64  • Android 12 (API 32) (emulator)
ipodune (mobile)            • 4671xxxxxxxxxxxxxxxxxxxxxxxxx434e • ios            • iOS 15.3.1 19D52
Chrome (web)                • chrome                                   • web-javascript • Google Chrome 98.0.4758.102
[1]: sdk gphone64 arm64 (emulator-5554)
[2]: ipodune (46717xxxxxxxxxxxxxxxxxxxxxxxxxx434e)
[3]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 2
Launching lib/main.dart on ipodune in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: JWxxxxxxxS9
Running Xcode build...                                                  
 └─Compiling, linking and signing...                      2,114ms
Xcode build done.                                            6.5s
Installing and launching...                                        14.4s
Syncing files to device ipodune...                                  48ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on ipodune is available at: http://127.0.0.1:59425/fKt92UBEFoI=/
The Flutter DevTools debugger and profiler on ipodune is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:59425/fKt92UBEFoI=/

何度か実行しているうちにエラーが出るようになった。

% flutter run -d  ipodune
Launching lib/main.dart on ipodune in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: JWxxxxxxS9
Running Xcode build...                                                  
 └─Compiling, linking and signing...                      2,277ms
Xcode build done.                                           14.0s
Could not run build/ios/iphoneos/Runner.app on 4671xxxxxxxxx3434e.
Try launching Xcode and selecting "Product > Run" to fix the problem:
  open ios/Runner.xcworkspace

Installing and launching...                                        41.2s
Error launching application on ipodune.

XCodeを使って、ios/Runner.xcworkspace から実行しろと?
XCodeから走らせると、明らかな設定誤りはないけれども時間切れで起動できない旨のエラーが出た。メッセージは以下

Details
Could not launch “Runner”
Domain: IDEDebugSessionErrorDomain
Code: 3
Failure Reason: timed out waiting for app to launch
User Info: {
    DVTErrorCreationDateKey = "2022-02-20 12:24:35 +0000";
    DVTRadarComponentKey = 855031;
    IDERunOperationFailingWorker = DBGLLDBLauncher;
    RawUnderlyingErrorMessage = "timed out waiting for app to launch";
}

最初はうまくいっていて、途中からおかしくなったので、こういう時はシステム再起動かと。
終了処理をしていて、バックグラウンドに回したままで放置したfultter run のプロセスに気づいた。この放置プロセスをkillすると timeoutが解消した。結果、手元のiPhoneでテストプログラムが動いた。まぁ細かいエラーは出ているのだが。

An Observatory debugger and profiler on ipodune is available at: http://127.0.0.1:61963/7P0OKYoaTlQ=/
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
The Flutter DevTools debugger and profiler on ipodune is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:61963/7P0OKYoaTlQ=/
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...

時々見かける、cache クリアしろというやつかも。詳細分かりませんが。
Hot reloadについては今のままだと、r キーを押す必要がある*1。だけど、修正したソースが遅延なく反映されるのはすごい。
■参考URL
[Flutter]iOS実機ビルド時に"iproxy"は、開発元を検証できないため開けません。と表示された場合の対処法
https://flutter.keicode.com/devenv/flutter-on-mac-catalina.php

対策方法の掲載ありがとうございます。

*1:手順書をよく読んで、IDE側でうまく設定すると自動更新されるのかもしれません。そこまで設定をやりこんでない