Open
Description
Feature Request
Plugin
PushNotifications
Description
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.
here:
build.gradle
template contains this:
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 likeawait PushNotifications.canRegister()
orawait PushNotifications.isSupported()
. That way, the user could call it and choose to not callregister
. This can be the only solution or a supplementary one. - handle this via env variables, in a more manual manner