🔥 発生した問題
Flutterではなく、Swift原生アプリをCocoaPodsで開発していた際、以下のようなエラーが発生:
Compiling for iOS 16.0, but module ‘RealmSwift’ has a minimum deployment target of iOS 18.1
Xcodeは、16.1.0でした
🧭 原因
Realmの一部バージョンでは、配布形式に.xcframework
(プリビルドバイナリ)を採用しており、
この中に「iOS 18.1以上でないと使えない」という情報が埋め込まれています。
つまり:
- アプリのDeployment Target:iOS 16.0
- Realm内部:iOS 18.1
このギャップにより、ビルドが通らない状態になります。
✅ 解決策:post_installでRealmのターゲットを強制修正
以下のようにPodfileに post_install
スクリプトを追加することで、
Realmのターゲット設定を強制的に16.0へ下げることができます。
platform :ios, '16.0'
target 'YourAppTarget' do
use_frameworks! :linkage => :static
pod 'RealmSwift', '10.43.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['Realm', 'RealmSwift'].include? target.name
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0'
end
end
end
end