Debugging log · Firebase
"Default FirebaseApp is not initialized in this process"
I wired up a Firebase feature, ran the app, and it crashed on the first Firebase call with a message telling me to call FirebaseApp.initializeApp(Context) first. The confusing part: I never call that anywhere, and Firebase samples don't either. That's because it's normally supposed to happen automatically — and when it doesn't, one specific piece is missing.
The short version: Firebase auto-initializes from your google-services.json via the google-services Gradle plugin. If the plugin isn't applied, or the JSON is missing or in the wrong place, that automatic setup never runs — so the "default app" doesn't exist when you call it.
The error
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
How initialization is supposed to work
You don't normally call initializeApp yourself. At build time the google-services plugin reads google-services.json and generates the config values; at startup a content provider Firebase ships reads those values and creates the default FirebaseApp before your code runs. When the error appears, that chain broke somewhere — the plugin didn't run, or it had no JSON to read.
Check these, in order
1. Is the google-services plugin applied?
You need it declared at the project level and applied in the app module. In the app module's build.gradle:
plugins {
id("com.android.application")
id("com.google.gms.google-services") // this line
}
Missing this is the single most common cause. Without it, the JSON is never processed and nothing initializes.
2. Is google-services.json in the right place?
It belongs in the app module directory (the app/ folder), not the project root. For build variants with different package names, it must contain a matching entry — or the plugin can't find config for the applicationId you're running.
3. Does the package name match?
The package_name inside google-services.json has to match your app's applicationId (including any suffix like .debug). A mismatch means the plugin generates no config for the variant you launched, and initialization silently no-ops.
4. Clean and rebuild
The plugin runs at build time. After adding it or replacing the JSON, do a clean build so the config is regenerated — a stale build can keep failing even after you've fixed the setup.
If you really do need to initialize manually
Automatic init covers almost everyone. If you have an unusual setup (no JSON, multiple Firebase projects, values from somewhere else), you can initialize explicitly early in Application.onCreate():
class App : Application() {
override fun onCreate() {
super.onCreate()
FirebaseApp.initializeApp(this) // or with explicit FirebaseOptions
}
}
But if you're hitting this error on a normal project, prefer fixing the plugin/JSON — that's almost always the real gap, and manual init just papers over it.
A subtle variant: the error only appears in a secondary process (a widget, a background service in its own process). Firebase initializes per process, so make sure whatever runs there also triggers initialization.
Package names and IDs above are placeholders — use your own project's values.