user924
user924

Reputation: 12123

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

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...

Upvotes: 59

Views: 3423

Answers (2)

Inidam Leader
Inidam Leader

Reputation: 629

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

Upvotes: 3

Blodhgard
Blodhgard

Reputation: 9385

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

Upvotes: 14

Related Questions