问题
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)
回答1:
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.
回答2:
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.** { *; }
来源:https://stackoverflow.com/questions/50392706/fcm-unable-to-instantiate-receiver-com-google-firebase-iid-firebaseinstanceidr