简体   繁体   中英

Admob causes NullPointerException in android apps

Since last week i'm getting a fatal error in my app in production release due some admob bug

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.overlay.n com.google.android.gms.ads.internal.overlay.AdOverlayInfoParcel.c' on a null object reference
       at com.google.android.gms.ads.internal.overlay.k.f(k.java)
       at com.google.android.gms.ads.internal.overlay.client.b.a(b.java:1)
       at fy.onTransact(fy.java:4)
       at android.os.Binder.transact(Binder.java:662)
       at com.google.android.gms.internal.ads.zzgu.zzb(zzgu.java:21)
       at com.google.android.gms.internal.ads.zzarl.onUserLeaveHint(zzarl.java:54)
       at com.google.android.gms.ads.AdActivity.onUserLeaveHint(AdActivity.java:32)
       at android.app.Activity.performUserLeaving(Activity.java:7470)
       at android.app.Instrumentation.callActivityOnUserLeaving(Instrumentation.java:1476)
       at android.app.ActivityThread.performUserLeavingActivity(ActivityThread.java:4034)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4016)
       at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:201)
       at android.app.ActivityThread.main(ActivityThread.java:6864)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

I was not able to reproduce the problem in test. but as the stack shows it is caused due some inner call of the admob api responding to android native events.

the versions i'm using:

'com.google.gms:google-services:4.3.4'
api "com.google.android.gms:play-services-location:17.1.0"
api 'com.google.android.gms:play-services-ads:19.5.0'

Best is try logging the Ad response id to basically see if there is a certain type of Ad crashing the App. If yes you need to search for Ad in Ad manager and block it from serving. https://developers.google.com/ad-manager/mobile-ads-sdk/android/crashlytics

Okay I Don't know the Perfect Solution of this because I think there is a bug in
com.google.android.gms:play-services-ads:19.5.0 or 19.6.0 look at this thread

the hacky solution is to use
com.google.android.gms:play-services-ads:19.3.0

This issue has been addressed by Google Admob SDK team. Based on them, the issue should no longer appear in a high frequency, and will be completely resolved in the near future.

From what i can see, i had zero occurrence of the issue in crashlytics after their feedback

Complete thread can be found here: https://groups.google.com/g/google-admob-ads-sdk/c/J6yNYabpeB0/m/zIkSSLEwAgAJ
I was opened by someone else, and i had followed it up with them sometime later.

The error disappeared with these lines:

gradle (app)
    defaultConfig {
        ...
        ...
        useLibrary 'org.apache.http.legacy'
    }

and in manifest

<application
    ...
    ...
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />
    ...
    ...
</application>

Update to latest version and check Internet permissions manifest.

implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.android.gms:play-services-ads:19.7.0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM