I've tried contacting support about this several times to no avail. This is an issue in Play Services that needs to be fixed, but gms doesn't have a public issue tracker.
Stacktrace:
Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.google.android.gms flg=0x4000010 bqHint=4 (has extras) } in com.google.android.gms.common.api.internal.bi@2f76cb84
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:988)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by java.lang.IllegalStateException: Task is already complete
at com.google.android.gms.common.internal.Preconditions.checkState(Preconditions.java:29)
at com.google.android.gms.tasks.zzu.zzc(zzu.java:123)
at com.google.android.gms.tasks.zzu.setResult(zzu.java:82)
at com.google.android.gms.tasks.TaskCompletionSource.setResult(TaskCompletionSource.java:8)
at com.google.android.gms.common.api.internal.zabu.zao(zabu.java:22)
at com.google.android.gms.common.api.internal.zal.zaq(zal.java:70)
at com.google.android.gms.common.api.internal.zao.zas(zao.java:2)
at com.google.android.gms.common.api.internal.zabq.onReceive(zabq.java:15)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:978)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
I found a few problems with this issue:
There's also this related crash (originates from zabu.zao):
Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.google.android.gms flg=0x4000010 (has extras) } in com.google.android.gms.common.api.internal.bi@1038aafb
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:912)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5597)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(GooglePlayServicesUtilLight.java:12)
at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(GoogleApiAvailabilityLight.java:5)
at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(GoogleApiAvailability.java:94)
at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(GoogleApiAvailabilityLight.java:3)
at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(GoogleApiAvailability.java:93)
at com.google.android.gms.common.api.internal.zabu.zao(zabu.java:20)
at com.google.android.gms.common.api.internal.zal.zaq(zal.java:70)
at com.google.android.gms.common.api.internal.zao.zas(zao.java:2)
at com.google.android.gms.common.api.internal.zabq.onReceive(zabq.java:15)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:902)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5597)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Thanks Alex, I'll figure out who on the Play services team should take a look at this.
When does this crash happen / is it easy to reproduce?
Awesome! And unfortunately, I have no idea when or how it happens (seems random). I just keep getting these crash reports though 🤷♂️. Seems pretty easy to avert a crash (at the expense of not getting correct behavior 100% of the time).
@SUPERCILEX the Play services SDK team is digging into this now, they have opened two internal tickets and are making some progress investigating. I am going to close this issue here since there's nothing the Firebase team can do about it but I will update you if we get a fix or need more information.
Awesome, thanks! 🙏
@SUPERCILEX ok internally the team already has fixes in place that will mitigate both of these issues and prevent them from being fatal. Still trying to determine how we get into those bad situations though (Context being null when it shouldn't and a TaskCompletionSource having its result already set).
This will be included in a future release of play-services-base although probably not the very next release since the team already has that one very planned out.
👏 Damn, that was fast! (I've been trying to get these fixed for months 😅)
Thanks for the solid crash reports!
Hi @SUPERCILEX 17.1.0 of play-services-base should fix these issues. Apologies for how long it takes to release the fix.
@aaronj1335 it took so long that @SUPERCILEX joined Google in the meantime :-)
But seriously, thanks for following up on this.
Awesome, thanks!
@SUPERCILEX I admire your tenacity in this as well as kotlin nullability correctness!
(how long will it take me to release that??!)
6801 times crashed app. it was working fine before.
java.lang.IllegalStateException
jz.b
java.lang.IllegalStateException:
at com.google.android.gms.common.internal.Preconditions.checkState (Unknown Source:29)
at com.google.android.gms.internal.ads.zzabc.getVersionString (Unknown Source:87)
at com.google.android.gms.ads.MobileAds.getVersionString (Unknown Source:16)
at com.google.ads.mediation.facebook.FacebookInitializer.initialize (FacebookInitializer.java:51)
at com.google.ads.mediation.facebook.FacebookMediationAdapter.initialize (FacebookMediationAdapter.java:86)
at com.google.android.gms.internal.ads.zzanm.zza (Unknown Source:364)
at com.google.android.gms.internal.ads.zzamu.dispatchTransaction (Unknown Source:194)
at com.google.android.gms.internal.ads.zzfn.onTransact (Unknown Source:12)
at android.os.Binder.transact (Binder.java:612)
at jz.b (com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:2)
at com.google.android.gms.ads.internal.mediation.client.h.a (com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:16)
at com.google.android.gms.ads.nonagon.initialization.g.run (Unknown Source:5)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at vw.a (Unknown Source)
at com.google.android.gms.ads.internal.util.g.a (com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:1)
at vw.dispatchMessage (Unknown Source)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6942)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
@sunjayjangam
Your issue is not related to this ticket, so preferably you should open a new one.
You need to call MobileAds.initialize and wait for the callback before making any other ads calls.
Most helpful comment
@aaronj1335 it took so long that @SUPERCILEX joined Google in the meantime :-)
But seriously, thanks for following up on this.