Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Android OS 8 WebVew with HTML select tag crash the app

I've got a hybrid Cordova Android app, and the app crashes when user tap on a drop-down box in my WebView running on Android OS 8. I've created a simple page with a <select> tag and the issue is reproducible. I've got a workaround which is to do my own pop up alert to select, but just wondering if this is happening to anyone else and whether this is an OS8 WebView bug.

Below is a simple page with <select> tag

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select

Below is my crash log

11:04:58.643 3208-3208/com.****.****E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.****.****, PID: 3208 android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2133)
    at android.content.res.Resources.getLayout(Resources.java:1142)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:416)
    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:407)
    at org.chromium.content.browser.input.SelectPopupAdapter.getView(SelectPopupAdapter.java:53)
    at android.widget.AbsListView.obtainView(AbsListView.java:2372)
    at android.widget.ListView.measureHeightOfChildren(ListView.java:1408)
    at android.widget.ListView.onMeasure(ListView.java:1315)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:721)
    at android.view.View.measure(View.java:21998)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2410)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1471)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
    at android.view.Choreographer.doCallbacks(Choreographer.java:723)
    at android.view.Choreographer.doFrame(Choreographer.java:658)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

My issue is not the same as this

Trying to open SELECT tag in Android WebView crashes the application

UPDATE on 9th Jan 2018: I haven't got a solution yet, my temporary workaround is remove the tag and just use an input. When user select this element, we pass the event to native code to pop up a dialog for selection and update the input once user made a selection.

UPDATE on 23rd March 2018: After some more investigation, I noticed that it only crashes if the WebView is in a Fragment, but not in an Activity.

I found below comments from this post:

Trying to open SELECT tag in Android WebView crashes the application

"When a SELECT tag is clicked, Android internally displays its options using a native AlertDialog. Webview must be created with an Activity context because AlertDialog instance needs an Activity context."

I believe this is a bug in Android, probably not handling Context properly for Fragment.

UPDATE 17th of April 2018:

As kenyee pointed out, from here https://issuetracker.google.com/issues/77246450, Google says

You mustn't subclass the resources object - this was never supported and was only possible by accident (which is why it's now marked deprecated). The framework needs to know about all the resources objects so that it can update them when webview is loaded (since webview adds additional paths to the asset manager).

Edit 29th November 2018 Seems this issue has bothered a lot of people.

  • The solution I've tried and tested to work is to not subclassing the Resource.
  • Updating compile sdk and supported library version worked for some people.
  • Adding a wrapper class to Resource may work, I've tried this approach during my initial investigation, it solved the Select crashing issue, still crashes when you click and hold on a text view to pop up the "COPY", "PASTE" options.
like image 467
Dennis Hui Avatar asked Sep 13 '17 23:09

Dennis Hui


3 Answers

I have same issue on Android 8.0 . finally i solve it. Try to update your compileSdkVersion to 26, and update your com.android.support:appcompat-v7 to 26.

like image 176
Steven Zhang Avatar answered Oct 16 '22 17:10

Steven Zhang


If anyone is still having this issue, I found that it wasn't even my code that was subclassing the Resources class but rather the Google support library version that I was using. Updated the support library version and it worked like a charm!

like image 45
Arash Tadayon Avatar answered Oct 16 '22 17:10

Arash Tadayon


In AndroidX land (limited to a minimum compileSDKVersion 28), I was also getting this issue on a Marshmallow emulator with a popup spinner. I don't go anywhere near Resources so this is still a platform issue with one of the support libs.

I managed to get it working - not by moving the webview to an Activity (although I did try that, it was unnecessary), - but by adding it programmatically with a wrapped context and a standard AppCompat theme:

val webView = WebView(ContextThemeWrapper(activity, R.style.Theme_AppCompat_Light))
binding.webViewContainer.addView(webView)

I don't understand wtf is going on here but right now it works. Good luck people!

EDIT I have looked into this a lot more and found the dependency which is causing issues for me. A particular version of the material components library is actually inducing this in webviews (1.1.0-alpha06 to be precise). I have asked a question on it here, with a sample project.

like image 3
Daniel Wilson Avatar answered Oct 16 '22 18:10

Daniel Wilson