Introduction
Firebase initialization on iOS in Flutter apps can fail for several reasons including a missing or misconfigured GoogleService-Info.plist file, bundle ID mismatch between the Firebase console and Xcode project, or issues with the FirebaseApp.configure() call in the iOS native code. The error typically manifests as a crash at app launch or a silent failure where Firebase services are unavailable.
Symptoms
- App crash on launch with:
`- *** Terminating app due to uncaught exception 'com.firebase.core',
- reason: '
[FIRApp configure];(FirebaseApp.configure()in Swift) could not find a valid GoogleService-Info.plist' `- Flutter console shows:
`- [firebase_core/initialized-failed] Firebase has not been correctly initialized.
`- Or silent failure where
FirebaseAuth.instancethrows: `- [core/not-initialized] Firebase has not been correctly initialized.
`- Works on Android but fails on iOS
Common Causes
GoogleService-Info.plistnot added to Xcode project or not in the Runner target- Bundle identifier in Xcode does not match the one registered in Firebase console
GoogleService-Info.plistnot set with "Target Membership" for the Runner target- CocoaPods not properly linking Firebase frameworks
- Missing
FirebaseCoreimport inAppDelegate.swift
Step-by-Step Fix
- 1.Verify GoogleService-Info.plist is in the correct location:
- 2.```bash
- 3.# Should be at:
- 4.ls ios/Runner/GoogleService-Info.plist
- 5.
` - 6.Check Target Membership in Xcode:
- 7.- Open
ios/Runner.xcworkspacein Xcode - 8.- Select
GoogleService-Info.plistin the project navigator - 9.- In the File Inspector, ensure "Target Membership" has
Runnerchecked - 10.- Verify it appears under
Copy Bundle Resourcesin Build Phases - 11.Verify bundle ID matches Firebase console:
- 12.```bash
- 13.# Check your bundle ID:
- 14.grep -r "PRODUCT_BUNDLE_IDENTIFIER" ios/Runner.xcodeproj/project.pbxproj
# Should match the iOS app registered at https://console.firebase.google.com # Common mismatch: com.example.app vs com.example.app.dev ```
- 1.Ensure FirebaseCore is configured in AppDelegate.swift:
- 2.```swift
- 3.import UIKit
- 4.import Flutter
- 5.import FirebaseCore // Required for manual configuration
@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { FirebaseApp.configure() // Must be called before any Firebase usage GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } ```
- 1.Reinstall pods and rebuild:
- 2.```bash
- 3.cd ios
- 4.rm -rf Pods Podfile.lock
- 5.pod install --repo-update
- 6.cd ..
- 7.flutter clean
- 8.flutter pub get
- 9.flutter build ios --no-codesign
- 10.
` - 11.Initialize Firebase in Dart before using any services:
- 12.```dart
- 13.import 'package:firebase_core/firebase_core.dart';
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: const FirebaseOptions( apiKey: 'YOUR_IOS_API_KEY', appId: 'YOUR_IOS_APP_ID', messagingSenderId: 'YOUR_SENDER_ID', projectId: 'YOUR_PROJECT_ID', iosBundleId: 'com.example.app', ), ); runApp(const MyApp()); } ```
Prevention
- Always run
flutterfire configureafter adding Firebase packages - Keep bundle IDs consistent across Firebase console and Xcode
- Add
GoogleService-Info.plistto version control (it contains no secrets) - Test Firebase initialization on a physical iOS device, not just simulator
- Use
Firebase.initializeApp()with explicit options in Dart