AdMob: MobileAds.initialize() - "java.lang.Integer cannot be cast to java.lang.String" for some devices
Asked Answered
U

2

59

Please vote to the issue tracker https://issuetracker.google.com/issues/330368298

enter image description here

I just noticed some crashes for my app by looking at Firebase Crashlytics which seems to be related to Google AdMob library which tries to use SharedPreferences but it fails to get a preference because of the cast exception:

enter image description here

enter image description here

Code text:

Fatal Exception: java.lang.ClassCastException
java.lang.Integer cannot be cast to java.lang.String
android.app.SharedPreferencesImpl.getString (SharedPreferencesImpl.java:302)
com.google.android.gms.ads.internal.scionintegration.a.onSharedPreferenceChanged (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:73)
com.google.android.gms.ads.internal.scionintegration.m.a (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:106)
com.google.android.gms.ads.nonagon.a.s (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:439)
com.google.android.gms.ads.nonagon.a.b (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:5)
com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl.getMobileAdsSettingManager (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:52)
com.google.android.gms.ads.internal.client.bx.bR (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:40)
m.ajn.onTransact (:com.google.android.gms.policy_ads_fdr_dynamite@[email protected]:21)
android.os.Binder.transact (Binder.java:1173)
obj.gL (:com.google.android.gms@[email protected] (190400-607434947):8)
com.google.android.gms.ads.internal.client.ay.getMobileAdsSettingManager (:com.google.android.gms@[email protected] (190400-607434947):12)
com.google.android.gms.ads.MobileAdsSettingManagerCreatorImpl.getMobileAdsSettingManager (:com.google.android.gms@[email protected] (190400-607434947):42)
com.google.android.gms.ads.internal.client.az.fL (:com.google.android.gms@[email protected] (190400-607434947):40)
obk.onTransact (:com.google.android.gms@[email protected] (190400-607434947):101)
android.os.Binder.transact (Binder.java:1173)
com.google.android.gms.internal.ads.zzavg.zzbh (com.google.android.gms:play-services-ads-base@@22.6.0:1)
com.google.android.gms.ads.internal.client.zzcp.zze (zzcp.java:169)
com.google.android.gms.ads.internal.client.zzeq.zza (zzeq.java:169)
com.google.android.gms.ads.internal.client.zzaq.zzc (com.google.android.gms:play-services-ads-lite@@22.6.0:169)
com.google.android.gms.ads.internal.client.zzax.zzf (com.google.android.gms:play-services-ads-lite@@22.6.0:126)
com.google.android.gms.ads.internal.client.zzax.zzd (com.google.android.gms:play-services-ads-lite@@22.6.0:126)
com.google.android.gms.ads.internal.client.zzej.zzA (com.google.android.gms:play-services-ads-lite@@22.6.0:17)
com.google.android.gms.ads.internal.client.zzej.zzm (zzej.java:53)
com.google.android.gms.ads.MobileAds.initialize (com.google.android.gms:play-services-ads-lite@@22.6.0:53)
com.MY_APP_PACKAGE.ads.AdMob.initAdmob (AdMob.kt:128)

Does anybody have this issue?

I have other apps which use 22.6.0 version of Admob and I didn't notice such crashes for them and for this app it happened only for 6 users (of ~230k users) but still... why it could happen..

Update:

Found out the same issue happens for others: https://groups.google.com/g/google-admob-ads-sdk/c/88UHAaWElsc

Updated 2:

Now I'm getting more crashes and now it effects other apps

p.s. also Admob Dashboard API was down today, so mb it's something related

Reddit thread

Google IssueTracker

Temporary solution: if you have Firebase Remote Config set up for your apps to disable ads, which also prevents calling MobileAds.initialize() if there a specific parameter for that you have added. In my case I unfortunately have parameters to enable/disable types of ads on the screens of my apps (banners, interstitials) only, but no parameters to prevent loading consent information (UMP library) and MobileAds.initialize(), but I will add it now for the future cases...

Uvea answered 19/3 at 19:12 Comment(17)
This seems like a new issue stemming from a change in Google. I'm using 'com.google.android.gms:play-services-ads:22.2.0' and tempt to update to 23.0 but don't really sure if it will be fixed. I think that the fact that it happened to both of us without any change from our part means that this is some external change made in Google's servers. I don't think version 23.0 will fix this though, but it worths a tryPackard
@OzShabat yeah, it makes sense, I guess we just to have wait for their response and updatesUvea
I've also reported the same issue here: issuetracker.google.com/issues/330368298 Hopefully they can remotely fix the issue. Forcing all users to update to a new version is definitely not an acceptable solution. We are seeing way more crashes on our side ~60k...Matchmark
@SimonMarquis omg... ~60k...Uvea
@OzShabat I get this exception in versions 23.0.0 & 22.6.0Circassia
yeap @Circassia this what I thought. No point in updating to the latest version nowPackard
Same for me. Thousands of crashes out of nowhere. I released a quick and dirty update and for now just catch the ClassCastException at MobileAds.initialize() until google fix this issue...Oliva
Hmm... @ToniKaufmann A simple Try and Catch on the MobileAds.initialize(this) {} will stop this crash? The crashes keep going up jesus christPackard
@Oz Shabat I'm pretty sure it works. Update is not live yet. But don't like this solution. Affected users don't get any ads but at least no crashes...Oliva
I've added this solution to the tracker. Any help will be appreciated it's getting a bit scary hahaPackard
@OzShabat I would be careful about overwriting the complete consent string. It will remove any consent the user has given in the past and can result in no fill or non personalized ads. I expect google to fix this issue soon...Oliva
Let us continue this discussion in chat.Packard
I started seeing this today too, clearing the play store and play services app data and cache data fixed it for one user. Also added the try catch band aid...Coronograph
Happening here as well. Could this have anything to do with the new programmatic limited ads with the UMP/GDPR consent? This feature was announced by Google to be live by end of Q1. I've turned them off in the AdMob UI to monitor the crashes (Settings -> Account -> Account controls -> Programmatic limited ads -> Off).Hispania
@Hispania this would make sense. I see percentage higher crashes in old versions without user consent implemented. These version should get limited ads. Also explain why only a limited percentage from our users get this crash (every EU user without consent)Oliva
Google is addressing the issue. For detailed updates, refer to their incident report: Google Ads Status. According to their latest update, "We expect to resolve the problem affecting a majority of users of AdMob by March 21, 2024, at 9:00 PM UTC. ... The issue causing the application to crash when initializing the Android Google Mobile Ads SDK has been identified and fixed. We are currently waiting for the changes to take effect on end-user devices."Art
I just see this same crash today and it's a sudden spike in firebase-Crashlytics. I am using play-services-ads:21.2.0.Rambo
E
14

The crash is actively investigated by Google and they claim that it has been already solved. You can find more details here: https://ads.google.com/status/publisher/incidents/ZDDr9AsgkrNxd7zHjU4c?hl=en

Egerton answered 20/3 at 9:25 Comment(2)
Some of my users are still facing a problem 2024-03-20 13.30 UTC.Alver
To speed up the fix, your user should restart the device or clear the Google Play cache and data.Egerton
L
3

It appears that employing try-catch blocks is currently the most viable approach (it's proven effective in our production environment). This practice serves as a pragmatic solution, especially for handling non-critical components like ad initialization, loading..., where failures shouldn't disrupt the core functionality of the application.

By wrapping these optional operations in try-catch blocks, we can gracefully handle any potential errors that may arise without jeopardizing the overall user experience. This adheres to a best practice of isolating and managing potential points of failure.

In the attached image, you can observe how this crash is handled as a non-fatal event in our scenario, further illustrating the effectiveness of this approach.

However, it's important to note that this approach may encounter occasional failures, especially due to internal operations in detached threads.

Non fatal event

Logy answered 21/3 at 2:9 Comment(1)
This user reports that a try-catch was not an effective workaround for this issue. I think it just ends up crashing the first time you load an advert instead (I tried skipping the call to MobileAds.initialize as it's optional and also ended up crashing with that other callstack).Popliteal

© 2022 - 2024 — McMap. All rights reserved.