If you’re working with Firebase in a Flutter iOS project, you may encounter errors related to Firebase header imports, especially when managing CocoaPods dependencies.
Fixing Firebase Header Issues in Flutter iOS Project
Step 1: Clean and Reinstall CocoaPods
flutter clean
rm -rf ios/Pods ios/.symlinks ios/Flutter/Flutter.podspec
cd ios
pod deintegrate
pod install --repo-update
cd ..
flutter pub get
Note: if pod install successful than you have to go next step otherwise issue is different
above steps: flutter clean
clears cached build files. | rm -rf
removes existing CocoaPods files to avoid conflicts. | pod deintegrate
resets CocoaPods settings. | pod install --repo-update
reinstalls and updates all dependencies.
Step 2: Modify the Podfile for compatibility. At the bottom of the Podfile, comment and add new content.. In our case, we set: platform :ios, ‘14.0’:
#target 'Runner' do
# use_frameworks!
# use_modular_headers!
#
# flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
# target 'RunnerTests' do
# inherit! :search_paths
# end
#end
###UPDATE ABOVE CONTENT WITH BELOW CONTENT
target 'Runner' do
use_frameworks! :linkage => :static # Use static linking instead of default dynamic frameworks
pod 'Firebase/Core', :modular_headers => true
pod 'Firebase/Messaging', :modular_headers => true
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
Step 3: Verify Firebase imports in the code. Locate the section in the file where the error occurs and replace it with the appropriate libraries :
//#import <Firebase/Firebase.h>
// REPLACE WITH BELOW CONTENT
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>
#import <firebase_core/FLTFirebasePlugin.h>
#import <FirebaseMessaging/FIRMessaging.h>
//#import <Firebase/Firebase.h>
Step 4: Open Xcode and Check Build Settings
Now open ios/Runner.xcworkspace. in Xcode
Step 5: In Xcode top menu Product then clean build folder and clear all issues then build > for testing
Conclusion: By following these steps, you can successfully fix Firebase header issues in a Flutter iOS project.
Other Articles: