Firebase
FirebaseApp
Initialization Error
Mobile App Development
Error Handling

Default FirebaseApp is not initialized

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Default FirebaseApp is not initialized means Firebase code ran before the default app instance was configured. In practice, this usually comes down to startup order, missing configuration files, or calling a Firebase API in the wrong process or lifecycle point.

Android: Initialize Early

In a standard Android setup, Firebase is usually initialized automatically when:

  • 'google-services.json is present in the app module'
  • The Google Services Gradle plugin is applied correctly
  • The app process starts normally

If you need manual initialization, do it in Application:

kotlin
1import android.app.Application
2import com.google.firebase.FirebaseApp
3
4class MyApp : Application() {
5    override fun onCreate() {
6        super.onCreate()
7        FirebaseApp.initializeApp(this)
8    }
9}

Then register the application class in AndroidManifest.xml.

iOS: Configure in App Startup

On iOS, the equivalent step is usually:

swift
1import UIKit
2import FirebaseCore
3
4@main
5class AppDelegate: UIResponder, UIApplicationDelegate {
6    func application(
7        _ application: UIApplication,
8        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9    ) -> Bool {
10        FirebaseApp.configure()
11        return true
12    }
13}

If Firebase services are used before this call, the initialization error appears.

Missing Config Files Cause the Same Symptom

Even correct startup code will fail if the project configuration is incomplete.

Check for:

  • 'google-services.json in the Android app module'
  • 'GoogleService-Info.plist in the iOS app target'
  • Correct bundle or package identifiers
  • Firebase dependencies installed correctly

The error message is about initialization, but the root cause can still be a missing or mismatched project config file.

Check the Build Setup Too

On Android, verify that the Google Services plugin is applied in the correct module so the configuration file is actually processed during the build. On iOS, confirm the plist is part of the app target and not merely present in the project navigator. A file that exists in the repository but is not included in the built app can still produce the same initialization error.

Initialization Order Matters

Another common mistake is calling Firebase from static initializers, singletons, or background components before the app startup path has completed.

For example, this can be too early:

kotlin
val db = com.google.firebase.firestore.FirebaseFirestore.getInstance()

if it runs before FirebaseApp.initializeApp(...).

The safe pattern is:

  • Initialize Firebase first
  • Access service singletons after that

Multiple Processes and Special Runtimes

Some Android apps use secondary processes for services or content providers. In that case, code may run in a process where Firebase was never initialized the way you expected. The error can look random until you realize different processes have different startup paths.

That is why "it works in the main activity but not in a background component" is such a common clue. The failing code may be running in a different process or before the normal application startup path has completed.

Common Pitfalls

  • Calling Firebase APIs before FirebaseApp has been configured.
  • Forgetting the platform config file or placing it in the wrong target or module.
  • Assuming the app is initialized in every Android process automatically.
  • Debugging the Firebase API call itself when the real issue is earlier startup configuration.

Summary

  • The error means Firebase services were accessed before the default app was initialized.
  • On Android, initialize early and verify google-services.json plus Gradle setup.
  • On iOS, call FirebaseApp.configure() during app startup and include the plist file.
  • Check config-file placement and bundle or package identifiers.
  • Most fixes come from correcting initialization order, not from changing the later Firebase call.

That is why startup sequencing is usually the first thing to inspect.


Course illustration
Course illustration

All Rights Reserved.