FirebaseCoreInternal-libraryに関するSwiftパッケージの静的ライブラリ統合エラー解決方法
問題の概要
FlutterまたはReact NativeプロジェクトでiOS向けに pod install
を実行した際、以下のエラーが発生することがあります:
[!] The following Swift pods cannot yet be integrated as static libraries:
The Swift pod `FirebaseCoreInternal-library` depends upon `GoogleUtilities-library`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
このエラーは、FirebaseのSwiftパッケージが静的ライブラリとして統合される際に、依存関係にある GoogleUtilities
ライブラリがモジュールマップを定義していないために発生します。
推奨ソリューション
ソリューション1: Expoプロジェクト向け(最新推奨)
Expo Build Propertiesの使用
Expoプロジェクトでは、expo-build-properties
プラグインを使用するのが最も確実な解決方法です。
パッケージのインストール
bashnpx expo install expo-build-properties
app.jsonの設定
json{ "expo": { "plugins": [ [ "expo-build-properties", { "ios": { "useFrameworks": "static", "podfileProperties": { "use_modular_headers!": true } } } ] ] } }
プロジェクトの再ビルド
bashnpx expo prebuild --clean # または npx expo prebuild
ソリューション2: React Native CLIプロジェクト向け
注意点
React Native Firebaseのメンテナンスチームによると、以下の回避策は一時的な解決策に過ぎず、将来的に完全にSwiftに移行するモジュールでは機能しなくなる可能性があります。
Podfileの修正例:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
target 'YourApp' do
config = use_native_modules!
# Firebase設定
use_frameworks! :linkage => :static
$RNFFirebaseAsStaticFramework = true
# モジュラーヘッダーの設定
pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'FirebaseCoreInternal', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true
# その他の設定
flags = get_default_flags()
use_react_native!(
:path => config[:reactNativePath],
:hermes_enabled => flags[:hermes_enabled],
:fabric_enabled => flags[:fabric_enabled],
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
# Flipperの設定(必要な場合)
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end
ソリューション3: 最小限の修正
シンプルに問題を解決したい場合は、Podfileに以下の行を追加するだけでも動作することがあります:
target 'YourApp' do
use_frameworks! :linkage => :static
use_modular_headers!
# 既存の設定
# ...
end
技術的背景
この問題は、Firebaseがバージョン9.0.0以降で静的ライブラリとしての統合方法を変更したことに起因しています。FirebaseのSwiftパッケージが増えるにつれて、従来の動的フレームワーク方式では問題が生じるようになりました。
重要な注意点
FirebaseFunctions
とFirebaseStorage
モジュールはuse_frameworks!
を必要とするため、これらのモジュールを使用する場合は静的ライブラリ方式では動作しない可能性があります- 将来的なFirebaseのアップデートでより多くのモジュールがSwiftに移行するため、長期的には
use_frameworks!
方式への移行が推奨されます
トラブルシューティング
よくある問題と解決策
「library not found for -lFirebase」エラー
- ソリューション:追加のFirebaseパッケージ指定を削除し、最小限の設定で試してみてください
リッチ通知が機能しない
- ソリューション:別のターゲットを追加して通知関連のパッケージのみ別設定にします
rubytarget 'richNotification' do pod 'FirebaseCoreInternal', :modular_headers => true pod 'Firebase/Messaging', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true end
Apple Silicon (M1/M2) チップでの問題
- ソリューション:Rosettaモードでの実行またはアーキテクチャ除外設定の追加
rubypost_install do |installer| installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end end
まとめ
FirebaseのiOS統合に関するこのエラーは、プロジェクトの設定と使用しているFirebaseのバージョンに依存します。Expoプロジェクトでは expo-build-properties
の使用を、React Native CLIプロジェクトでは use_frameworks! :linkage => :static
とモジュラーヘッダーの組み合わせを推奨します。
ただし、長期的な互換性を考慮すると、React Native Firebaseチームが推奨するように、将来的には use_frameworks!
を使用した方式への移行を検討する必要があります。
最終確認
変更を加えた後は、必ず以下のコマンドを実行して変更を適用してください:
cd ios && pod install --repo-update