Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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) 
like image 384
user8400863 Avatar asked May 23 '20 08:05

user8400863


1 Answers

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.

like image 138
Juan Ignacio Avatar answered Oct 06 '22 01:10

Juan Ignacio