エラー
「Custom Keyboard Extension」を追加した際、Xcode のビルドサイクルで 循環 (Cycle) エラー が発生。
Could not build the precompiled application for the device.
Error (Xcode): Cycle inside Runner; building could produce unreliable results.
Cycle details:
→ Target 'Runner' has copy command from '/Users/x/dev/xxxxx/build/ios/Debug-iphoneos/xxxxx.appex' to
'/Users/x/dev/xxxxx/build/ios/Debug-iphoneos/Runner.app/PlugIns/xxxxx.appex'
○ Target 'Runner'
○ That command depends on command in Target 'Runner': script phase “Thin Binary”
○ Target 'Runner' has process command with output '/Users/x/dev/xxxxx/build/ios/Debug-iphoneos/Runner.app/Info.plist'
○ Target 'Runner' has copy command from '/Users/x/dev/xxxxx/build/ios/Debug-iphoneos/xxxxx.appex' to
'/Users/x/dev/xxxxx/build/ios/Debug-iphoneos/Runner.app/PlugIns/xxxxx.appex'
原因
Xcode の ビルドシステムの依存関係 と コピー処理の順序 に問題があり、適切に xxxxx.appex が処理されず、循環エラーが発生。
Xcode のビルドシステムでは、以下の順序で処理が実行される。
1.ターゲットのコンパイル(個々のターゲットの Swift / Objective-C ファイルをコンパイル)
2.Thin Binary(スクリプト処理)(不要なアーキテクチャのバイナリを削除)
3.CP Embed Pods Frameworks(CocoaPodsのフレームワークをコピー)
4.Embed App Extensions(アプリ拡張機能の埋め込み)
通常、この流れで問題なくビルドされるが、「Custom Keyboard Extension」などの特殊な拡張機能 がある場合、次の問題が発生する。
「Thin Binary」や「CP Embed Pods Frameworks」の段階で xxxxx.appex を参照しようとするが、まだ xxxxx.appex が埋め込まれていない。
存在しない拡張機能を参照しようとしてビルドエラーが発生する。
解決策
「Build Phases」の順番を調整し、「Embed Foundation Extension」を「Thin Binary」や 「CP Embed Pods Frameworks」の前に配置 する。
修正のポイント
xxxxx.appexを先にビルドし、適切に Runner.app にコピーされるようにする。
その後 Thin Binary や CP Embed Pods Frameworks が xxxxx.appex を正しく参照できる状態にする。
この調整により、Xcode の「Cycle inside Runner」エラーが解消され、正しくビルドできるようになる。