I am having some 'fun' with an Android WebView.
I am using it to show a login screen and then intercept the auth code on response. Should be pretty straightforward...
My WebView loads and displays absolutely fine if I only override shouldOverrideUrlLoading but if I override (just as autocompleted by Android Studio):
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse {
return super.shouldInterceptRequest(view, request)
}
with no other changes it crashes immediately at runtime with a native crash
A/chromium: [FATAL:jni_android.cc(259)]
followed by
A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 16220 (TaskSchedulerFo), pid 16175 (eports.internal)
Weirdly if I make the response nullable the WebView works once more. However adding anything else into the shouldInterceptRequest method makes it fall over with the same error.
So this works:
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
return super.shouldInterceptRequest(view, request)
}
But this crashes with the above crash:
override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
val url = view?.url
return super.shouldInterceptRequest(view, request)
}
This seems like a really odd issue, and makes no sense to me why adding a val assignment would make any difference at all.
I have been researching the error and suggestions were to add
webView.destroy()
in the activity/fragments onDestroy/onDestroyView, this does not help unfortunately.
Behaviour is the same on Device and Emulator, and on Android sdk 22 and 28.
Has anyone seen anything like this before? I feel like I am probably missing something obvious.
In case it is useful for anyone I also have the Breakpad Microdump generated also, it is too large to post in this question. But let me know if it, or a subset of it, may help diagnose!