ANRs with the same stack trace started appearing in my Google Play Console on around June 4. I can't say what the exact frequency of them is, but it is the most common ANR in the latest version of my app and likely will have a significant effect on Android Vitals.
The ANRs started appearing without me having updated the app in almost two months - zero occurences before these dates and now there are dozens daily. I have since updated the app (on June 9) to use the latest mobile ads SDK (play-services-ads:17.2.1) and the latest Android SDK (28), but the same ANRs appear in the updated app as well, so I don't think it's necessarily an issue with the SDKs.
I have found a simple way to reproduce something that looks related locally. The ANR is caused by the two threads getting deadlocked and this is a way to reproduce a case where a webview method is called on a wrong thread, with a similar stack trace. It seems like a likely culprit.
If you have variable 'InterstitialAd interstitial' and load an ad into it but don't display it, and then later set 'interstitial = null' to let it be GC'd, it apparently gets stuck somehow. Now if you put the app into background, after a few seconds you can see this in Logcat:
2019-06-12 12:10:24.305 5071-5088/com.example.app W/WebView: java.lang.Throwable: A WebView method was called on thread 'FinalizerDaemon'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {e15b91b} called on null, FYI main Looper is Looper (main, tid 2) {e15b91b}) at android.webkit.WebView.checkThread(WebView.java:2695)
at android.webkit.WebView.loadUrl(WebView.java:969)
at com.google.android.gms.ads.internal.webview.v.e(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:1)
at com.google.android.gms.ads.internal.webview.v.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:9)
at com.google.android.gms.ads.internal.webview.t.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:10)
at com.google.android.gms.ads.nonagon.ad.interstitial.b.finalize(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:2)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
at java.lang.Daemons$Daemon.run(Daemons.java:103)
at java.lang.Thread.run(Thread.java:764)
2019-06-12 12:10:24.343 5071-5088/com.example.app D/StrictMode: StrictMode policy violation: android.os.strictmode.WebViewMethodCalledOnWrongThreadViolation at android.webkit.WebView.checkThread(WebView.java:2695)
at android.webkit.WebView.loadUrl(WebView.java:969)
at com.google.android.gms.ads.internal.webview.v.e(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:1)
at com.google.android.gms.ads.internal.webview.v.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:9)
at com.google.android.gms.ads.internal.webview.t.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:10)
at com.google.android.gms.ads.nonagon.ad.interstitial.b.finalize(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:2)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
at java.lang.Daemons$Daemon.run(Daemons.java:103)
at java.lang.Thread.run(Thread.java:764)
2019-06-12 12:10:24.345 5071-5088/com.example.app W/Ads: Could not call loadUrl. java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'FinalizerDaemon'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {e15b91b} called on null, FYI main Looper is Looper (main, tid 2) {e15b91b})
at android.webkit.WebView.checkThread(WebView.java:2700)
at android.webkit.WebView.loadUrl(WebView.java:969)
at com.google.android.gms.ads.internal.webview.v.e(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:1)
at com.google.android.gms.ads.internal.webview.v.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:9)
at com.google.android.gms.ads.internal.webview.t.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:10)
at com.google.android.gms.ads.nonagon.ad.interstitial.b.finalize(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:2)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
at java.lang.Daemons$Daemon.run(Daemons.java:103)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.Throwable: A WebView method was called on thread 'FinalizerDaemon'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {e15b91b} called on null, FYI main Looper is Looper (main, tid 2) {e15b91b})
at android.webkit.WebView.checkThread(WebView.java:2695)
at android.webkit.WebView.loadUrl(WebView.java:969)
at com.google.android.gms.ads.internal.webview.v.e(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:1)
at com.google.android.gms.ads.internal.webview.v.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:9)
at com.google.android.gms.ads.internal.webview.t.destroy(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:10)
at com.google.android.gms.ads.nonagon.ad.interstitial.b.finalize(:com.google.android.gms.policy_ads_fdr_dynamite@20290000@20290000.249178941.249178941:2)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
at java.lang.Daemons$Daemon.run(Daemons.java:103)
at java.lang.Thread.run(Thread.java:764)
I tried this on two devices and was able to reproduce it on both:
- Nokia 6.1, Android version 9.0
- Xiaomi Redmi Note 5A, Android version 7.1.2
The issue can be reproduced with the test interstitial and video ad units:
- Test Interstitial: ca-app-pub-3940256099942544/1033173712
- Test Interstitial Video: ca-app-pub-3940256099942544/8691691433