Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter: FirebaseOptions cannot be null when creating the default app

ErrorFirebaseOptions cannot be null when creating the default app.

Short answer

Firebase started without any project settings. Either initializeApp was called without options on a platform that has no native config file, or the Android Google services plugin never turned google-services.json into settings. Run flutterfire configure, pass DefaultFirebaseOptions.currentPlatform, and check the Android plugin.

  • Applies to Flutter 3.35, firebase_core 3.x, FlutterFire CLI
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See how your main() starts Firebase, and whether the generated options file exists.

    grep -n "initializeApp" lib/main.dart
    ls lib/firebase_options.dart
  2. 2Match what you see, then jump to its fix

    1. 1Firebase.initializeApp() with empty parentheses, or no lib/firebase_options.dartinitializeApp is called without optionsFix
    2. 2It works on one platform and fails on another one you added laterfirebase_options.dart was made before this platform was addedFix
    3. 3Android only, and the app has no options argument or the plugin line is missingOn Android, google-services.json never became settingsFix

What does the error look like?

  • FirebaseOptions cannot be null when creating the default app.

Cause 1 of 3

initializeApp is called without options

1Check

The Flutter setup guide generates firebase_options.dart with flutterfire configure and passes its options to initializeApp. A bare call gives Firebase nothing to read on platforms without a native config file.

sed -n '1,25p' lib/main.dart

2Fix

Generate the file, then pass the options. Call WidgetsFlutterBinding.ensureInitialized() before the awaited initialization.

dart pub global activate flutterfire_cli
flutterfire configure

// lib/main.dart
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

3Verify

Stop the app completely and run it again; the error should not return.

flutter run

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 3

firebase_options.dart was made before this platform was added

1Check

The setup guide says to run flutterfire configure again whenever you add a platform. Open the generated file and look for a section for the platform that fails.

grep -n "static const FirebaseOptions" lib/firebase_options.dart

2Fix

Run the configure command again and select every platform you ship.

flutterfire configure

3Verify

The file now lists options for that platform. Rebuild and run it.

flutter run

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 3

On Android, google-services.json never became settings

1Check

Firebase's Android guide puts google-services.json in the app module folder and applies the Google services Gradle plugin, which reads it. Check both.

ls android/app/google-services.json
grep -rn "google-services" android/app/build.gradle* android/build.gradle* android/settings.gradle*

2Fix

Put the file in android/app and apply the plugin id com.google.gms.google-services in the app module's plugins block, declared with a version at the project level. The package name in the file must match your app's application ID.

// android/app/build.gradle.kts
plugins {
  id("com.android.application")
  id("com.google.gms.google-services")
}

3Verify

Clean and rebuild so the plugin runs again.

flutter clean
flutter run

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Treat firebase_options.dart as generated code and commit it, then rerun flutterfire configure when platforms change.
  • Always await initializeApp before runApp.
  • Match the Android application ID to the one registered in Firebase.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Flutter Android: Failed to load FirebaseOptions from resource

Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.

On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.