0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CocoaPodsでRealm使用時にiOS 18.1エラーが出たときの対処法

Posted at

🔥 発生した問題

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?