Firebase iOS Pods Static Library Integration
Problem
When integrating Firebase with Flutter or React Native apps on iOS, you may encounter the error:
[!] 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.
This occurs because newer versions of Firebase SDKs require static framework linking and modular headers to work properly with Swift-based dependencies.
Solutions
For Flutter Projects
Add the following to your ios/Podfile
:
target 'Runner' do
use_frameworks! :linkage => :static
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
For React Native Projects
Option 1: Configure with expo-build-properties (Expo)
npx expo install expo-build-properties
{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"ios": {
"useFrameworks": "static",
"podfileProperties": { "use_modular_headers!": true }
}
}
]
]
}
}
After configuration, run:
npx expo prebuild --clean
Option 2: Manual Podfile Configuration
Modify your ios/Podfile
with these settings:
platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
target 'YourApp' do
config = use_native_modules!
use_frameworks! :linkage => :static
$RNFirebaseAsStaticFramework = true
# Essential Firebase pods with modular headers
pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'FirebaseCoreInternal', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true
# ... rest of your configuration
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end
Option 3: Minimal Configuration
If you only need basic Firebase functionality:
target 'YourApp' do
config = use_native_modules!
pod 'FirebaseCore', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true
# ... rest of configuration
end
Important Considerations
WARNING
Using use_frameworks!
without :linkage => :static
may conflict with Flipper debugging tools. If you need Flipper, use the modular headers approach instead.
DANGER
Some Firebase modules (particularly Firebase Functions and Firebase Storage) may not work with static frameworks. For these cases, consider alternative solutions like using axios for API calls or AWS S3 for file storage.
Migration Recommendation
For Expo users experiencing persistent issues with expo-firebase-analytics
, consider migrating to React Native Firebase:
# Follow the official migration guide
npx expo install @react-native-firebase/app
Official migration resources:
Troubleshooting
After making Podfile changes, always run:
cd ios
pod install --repo-update
If you encounter build issues, try cleaning the project:
npx expo prebuild --clean
# or for React Native CLI
cd ios && rm -rf Pods Podfile.lock && pod install
Conclusion
The Firebase iOS integration error occurs due to incompatible linking settings between Swift pods and static libraries. The solutions provided address this by either configuring static framework linkage with modular headers or using the expo-build-properties plugin for Expo projects. Choose the approach that best fits your project's requirements and Firebase module dependencies.