Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM : Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver:

App is crashing while receiving push notification in Oreo(8.0) only .

java.lang.RuntimeException: Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassCastException: android.content.ContextWrapper cannot be cast to android.app.ContextImpl
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3236)
        at android.app.ActivityThread.-wrap17(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
like image 686
Supz Avatar asked Dec 08 '22 14:12

Supz


2 Answers

I was facing the same issue when using Calligraphy library. Even it was crashing the first time after installing when Firebase requests a token for the first time. Not only receiving push notifications.

My error was I was overriding attachBaseContext method in my Application class to return a ContextWrapper object, but was only needed in Activities.

So to resume my solution is to remove attachBaseContext in Application class and move it or just place it into activities.

like image 191
Rubén Viguera Avatar answered Jan 18 '23 23:01

Rubén Viguera


This might help; add these to your proguard if you are using it!

-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.** { *; }
-keep class com.google.firebase.** { *; }
like image 29
kevoroid Avatar answered Jan 18 '23 21:01

kevoroid