🐡

# Flutterで作ったiOSアプリを自分のiPhoneで試す際に詰まったこと:アイコンは出るのにタップで落ちる

に公開

※本記事は発生した問題についてAIとの対話を通じて原因を特定し、
その解決プロセスと結論をAIに整理・執筆してもらったものです。

やりたいこと

  • Flutterアプリを自分のiPhoneで動作確認したい
  • Apple Developer Program(有料)には入らない
  • 配布は不要

起きたこと

インストールできてアイコンは出るが、タップすると即落ちる

端末ログ(flutter logs など)にこれが出た:

[ERROR:flutter/runtime/ptrace_check.cc(75)] Could not call ptrace(PT_TRACE_ME): Operation not permitted
Cannot create a FlutterEngine instance in debug mode without Flutter tooling or Xcode.

To launch in debug mode in iOS 14+, run flutter run from Flutter tools, run from an IDE with a Flutter IDE plugin or run the iOS project from Xcode.
Alternatively profile and release mode apps can be launched from the home screen.

原因

iOS 14+ では Flutterのdebugビルドをホーム画面から単体起動できない(Flutter tooling / Xcodeにattachされている前提)。
そのため、debug版が入っていると「タップすると落ちる」ように見える。

試したこと

1) Pod掃除

(今回の本質はPodではなくdebug単体起動の仕様だったが、定番なので実施)

flutter clean
rm -rf ios/Pods ios/.symlinks ios/Podfile.lock
flutter pub get
cd ios && pod install && cd ..

2) flutter run -d <id> --release を試したが、なぜかdebugのままに見えた

「Releaseで入れればホーム画面から起動できるはず」と思って --release を付けたが、手元ではうまくいかず、
ホーム画面から起動すると同じ ptrace エラーが出続けた。

この手の「releaseを入れたつもりなのにdebugが起動している」ケースは、だいたい以下の罠がある:

  • 別の端末IDに入れているflutter devices のID取り違え)
  • 端末に 古いdebug版が残っていてそれを起動している(上書きされていない/別ターゲット)
  • Flutter/Xcodeの構成・キャッシュ都合で期待通りになっていない

3) --no-attach が使えなかった

自分のFlutter環境では以下になった:

Could not find an option named "--no-attach".

(Flutterのバージョン差でオプションが無い可能性)

解決:XcodeのRunをReleaseにして実機へ入れ直す

  1. ios/Runner.xcworkspace を開く
  2. Product > Scheme > Edit Scheme...
  3. 左の RunBuild Configuration = Release に変更
  4. 実機を選んで ▶︎ Run

→ Release版が入るので、ホーム画面から単体起動できるようになった(ptrace エラーが消えた)。

Discussion