You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make PushNotifications.register reject/throw instead of crashing the app #2370
When google-services.json is not present, calling PushNotifications.register crashes the app.
The app crashes with
java.lang.IllegalStateException:
Default FirebaseApp is not initialized in this process com.capacitor.app.
Make sure to call FirebaseApp.initializeApp(Context) first.
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
So, I would have expected it to automatically gracefully handle this, or at least throw an error we can handle from PushNotifications.register. That way, all environments, including dev environments, do not have to set up google-services.json and is able to run without push notifications.
Platform(s)
Android
iOS: should have a workaround, as it's called through the app delegate, but still prefer a solution
Preferred Solution
It should catch the error, then execute call.reject(error) to throw an error that can be handled in JS-side.
Alternatives
Gracefully handle the error by just logging a message, similar to what's done in build.gradle.
Offer a separate method to check if the requirements are present (e.g. google-services.json). It could be something like await PushNotifications.canRegister() or await PushNotifications.isSupported(). That way, the user could call it and choose to not call register. This can be the only solution or a supplementary one.
handle this via env variables, in a more manual manner
Still the case in 8.1.3 (Capacitor 8.5). Details and the local patch we use:
If google-services.json is missing (or the google-services Gradle plugin is not applied), PushNotifications.register() calls FirebaseMessaging.getInstance(), which throws IllegalStateException: Default FirebaseApp is not initialized in this process. The exception
is thrown on the CapacitorPlugins handler thread and Capacitor rethrows it as a RuntimeException, so the whole app is killed. JavaScript cannot catch it.
Expected: the call is rejected (e.g. code FIREBASE_NOT_CONFIGURED) so apps can run without
push, for example during development or in builds where push is not set up yet.
Patch we apply locally:
privatebooleanfirebaseBereit(PluginCallcall) {
if (FirebaseApp.getApps(getContext()).isEmpty()) {
call.reject("Firebase is not configured (google-services.json missing)", "FIREBASE_NOT_CONFIGURED");
returnfalse;
}
returntrue;
}
@PluginMethodpublicvoidregister(PluginCallcall) {
if (!firebaseBereit(call)) return;
...
}
Activity
kaypaerschFondo commentedon Oct 12, 2026
Still the case in 8.1.3 (Capacitor 8.5). Details and the local patch we use:
If
google-services.jsonis missing (or the google-services Gradle plugin is not applied),PushNotifications.register()callsFirebaseMessaging.getInstance(), which throwsIllegalStateException: Default FirebaseApp is not initialized in this process. The exceptionis thrown on the
CapacitorPluginshandler thread and Capacitor rethrows it as aRuntimeException, so the whole app is killed. JavaScript cannot catch it.Expected: the call is rejected (e.g. code
FIREBASE_NOT_CONFIGURED) so apps can run withoutpush, for example during development or in builds where push is not set up yet.
Patch we apply locally:
(same guard in
unregister). Happy to open a PR.