Android fetch UserAgent crash

crash
android
bug

#1

I find and solve this crash bug, and I created PR at GitHub.

Catch AndroidRuntimeException that could be raised by the WebSettings.getDefaultUserAgent() in some custom ROMs (e.g. OPPO, HTC, Sony, ASUS, Xiaomi …).

Crashlytics Issue Details Screenshot:

Crash StackTrace:

Fatal Exception: android.util.AndroidRuntimeException: java.lang.RuntimeException: Invalid reflection
       at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:146)
       at android.webkit.WebSettings.getDefaultUserAgent(WebSettings.java:1244)
       at com.mopub.network.Networking.getUserAgent(Networking.java:133)
       at com.mopub.network.Networking.getRequestQueue(Networking.java:63)
       at com.mopub.nativeads.MoPubNative.requestNativeAd(MoPubNative.java:192)
       at com.mopub.nativeads.MoPubNative.loadNativeAd(MoPubNative.java:177)
       at com.mopub.nativeads.MoPubNative.makeRequest(MoPubNative.java:152)
       at com.mopub.nativeads.MoPubNative.makeRequest(MoPubNative.java:137)
       ...

#2

Hi @HearSilent, thanks for creating the PR! The team is internally considering the try/catch approach, and would merge it in the future.


#3

Hi MoPub SDK team,
I’ve seen this issue in our app again in recent days (about “500 crashes” per day last week),
and I noticed that the “Android System WebView” app on the Google Play also got an update last weeek
(https://play.google.com/store/apps/details?id=com.google.android.webview)

Is this issue relevant to the webview update? and when is this PR ready to be merged?

Thanks.


#4

Hello!

Thanks for reaching out. Do you have a stack trace for that crash? It might or might not be the same crash as originally reported on this thread, so having a stack trace to compare will help determine that.

Thank you!


#5

Hi,

Here is the stack trace from Google Play console:

========================================
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$1000(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1371)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Method.java:0)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
Caused by: android.util.AndroidRuntimeException:
at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
at android.webkit.WebSettings.getDefaultUserAgent(WebSettings.java:1405)
at com.mopub.network.Networking.getUserAgent(Networking.java:0)
at com.mopub.network.Networking.getRequestQueue(Networking.java:0)
at .getRequestQueue(Networking.java:0)
at com.mopub.nativeads.MoPubNative.loadNativeAd(MoPubNative.java:0)

Hope this helps.

Thanks!


#6

Thanks! It does look like the same crash. It seems to occur on devices running on custom ROMs, and might not be related to the WebView update if your devices are not on custom ROMs.

There is no plan on merging the PR at this time, although internally we are considering it. I will bump up the priority so the SDK Engineering team can prioritize it.

Thanks,

Vu Chau
MoPub Support