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.instance throws:
  • `
  • [core/not-initialized] Firebase has not been correctly initialized.
  • `
  • Works on Android but fails on iOS

Common Causes

  • GoogleService-Info.plist not 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.plist not set with "Target Membership" for the Runner target
  • CocoaPods not properly linking Firebase frameworks
  • Missing FirebaseCore import in AppDelegate.swift

Step-by-Step Fix

  1. 1.Verify GoogleService-Info.plist is in the correct location:
  2. 2.```bash
  3. 3.# Should be at:
  4. 4.ls ios/Runner/GoogleService-Info.plist
  5. 5.`
  6. 6.Check Target Membership in Xcode:
  7. 7.- Open ios/Runner.xcworkspace in Xcode
  8. 8.- Select GoogleService-Info.plist in the project navigator
  9. 9.- In the File Inspector, ensure "Target Membership" has Runner checked
  10. 10.- Verify it appears under Copy Bundle Resources in Build Phases
  11. 11.Verify bundle ID matches Firebase console:
  12. 12.```bash
  13. 13.# Check your bundle ID:
  14. 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. 1.Ensure FirebaseCore is configured in AppDelegate.swift:
  2. 2.```swift
  3. 3.import UIKit
  4. 4.import Flutter
  5. 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. 1.Reinstall pods and rebuild:
  2. 2.```bash
  3. 3.cd ios
  4. 4.rm -rf Pods Podfile.lock
  5. 5.pod install --repo-update
  6. 6.cd ..
  7. 7.flutter clean
  8. 8.flutter pub get
  9. 9.flutter build ios --no-codesign
  10. 10.`
  11. 11.Initialize Firebase in Dart before using any services:
  12. 12.```dart
  13. 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 configure after adding Firebase packages
  • Keep bundle IDs consistent across Firebase console and Xcode
  • Add GoogleService-Info.plist to 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