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:
|
public void register(PluginCall call) { |
|
FirebaseMessaging.getInstance().setAutoInitEnabled(true); |
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 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
Additional Context
#1412
Feature Request
Plugin
PushNotifications
Description
When
google-services.jsonis not present, callingPushNotifications.registercrashes the app.The app crashes with
here:
capacitor-plugins/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java
Lines 102 to 103 in 10cf0ed
build.gradletemplate contains this: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 upgoogle-services.jsonand is able to run without push notifications.Platform(s)
Preferred Solution
It should catch the error, then execute
call.reject(error)to throw an error that can be handled in JS-side.Alternatives
build.gradle.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.Additional Context
#1412