Ionic Capacitor firebase push notification, error:Default FirebaseApp is not initialized in this process
Asked Answered
F

1

9

I am new to Capacitor and have migrating my Cordova project to Capacitor.

I trying to get my notification messages working. Therefore i followed the steps shown in https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/

Once i build my project, i am opening the project and Android Studio starts. I preform a run, and the app the starts to get downloaded on to my phone, which i then run.

And i get this error message shown below when it comes registering my phone for notification messages.

Am i missing a step?

The google-services.json is also placed in Andriod-->App

Thanks

 E/Capacitor: Serious error executing plugin
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
        at com.getcapacitor.Bridge$1.run(Bridge.java:515)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.aardra.cloud. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
        at com.google.firebase.messaging.FirebaseMessaging.getInstance(com.google.firebase:firebase-messaging@@20.1.2:1)
        at com.getcapacitor.plugin.PushNotifications.register(PushNotifications.java:82)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
        at com.getcapacitor.Bridge$1.run(Bridge.java:515) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
E/AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
    Process: com.aardra.cloud, PID: 749
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.getcapacitor.Bridge$1.run(Bridge.java:524)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
        at com.getcapacitor.Bridge$1.run(Bridge.java:515)
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.aardra.cloud. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
        at com.google.firebase.messaging.FirebaseMessaging.getInstance(com.google.firebase:firebase-messaging@@20.1.2:1)
        at com.getcapacitor.plugin.PushNotifications.register(PushNotifications.java:82)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
        at com.getcapacitor.Bridge$1.run(Bridge.java:515) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
Fabaceous answered 23/5, 2020 at 8:6 Comment(2)
It seems when using appflow, the ios firebase file is not being placed into the project correctly.Fabaceous
Are you using Appflow?Fabaceous
H
15

I had the same problem. In my case I forgot to put google-services.json in android/app folder.

Verify:

  1. google-services.json be in android/app folder and your Android package name should match the appId from your capacitor.config.json file. We used com.mydomain.myappname for this Capacitor app ID, so that is what we’ll use for this entry.
  2. capacitor.config.json has PushNotifications setup:
    {
     ...
     "plugins": {
        "SplashScreen": {
         ...
        },
        "PushNotifications": {
            "presentationOptions": ["badge", "sound", "alert"]
        }
     },
     ...
    }

Then build your js project and sync.

npx cap sync android
npx cap open android

And build your Android app or test in an emulator.

Housemaster answered 26/11, 2020 at 20:52 Comment(1)
i have the 2 config and i have the same error , any other idea?Lifer

© 2022 - 2024 — McMap. All rights reserved.