Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView Has started crashing on Android 9

Hello Expert Android Developers:

We have an android app and our basic workflow is as below

  1. User is sent a link via email or text message
  2. User clicks on the link and a page open on Chrome or Android default browser and have a button named JOIN
  3. User clicks on this JOIN button and our app is launched and a page is displayed in webview asking the User to enter the first name, last name and phone/email and then the user clicks on a button named INITIATE
  4. We validate the information - if the user is new, we create a record, it user is existing, we update it etc and then show a popup informing that his session would be recorded.
  5. As soon as the user clicks on OK on the popup and then the control exists the webview and the user is on a native android page.

Problem As soon as the OK button is tapped on the webview where our native app page would launch normally until a few weeks ago, the app crashes and we would be taken back to the start of the webview page asking us to enter the details.

Please note the below caveats:

  • First of all, this is happening only in the case of Android 9. We have tested this on Samsung Galaxy S8 and S9. And it doesn't happen every single time but it happens rather regularly, I would say sometimes even 2 out of 3 times. In the best of the times, it has happened 2 out of 10 times but it happens.
  • This code has been running successfully for the past 1 year or so and we never had this problem. It has only started happening in the last 3-4 weeks.
  • We also have an iOS app, where the same problem is not observed.

Here is a code snippet that may help - This is how we are loading the webview.

webview = findViewById(R.id.webview);
    webview.setVisibility(View.VISIBLE);
    final ProgressDialog pd = ProgressDialog.show(ActivtyName.this, "", "Please wait", true);
    webview.setGeolocationEnabled(true);
    webview.setMixedContentAllowed(true);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setDomStorageEnabled(true);
    webview.getSettings().setLoadWithOverviewMode(true);

    webview.setWebChromeClient(new WebChromeClient()

=======We override a lot of methods here followed by

webview.setWebViewClient(new WebViewClient()

=======We override methods here.

Any idea what might be going on? We have tried looking at the logs while debugging via USB mode, but we don't see much in logs except what is shown on the Android Console like below:

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> com.a****d.xyzapp <<<

backtrace:

#00  pc 0000000001b61620  /data/app/com.android.chrome-DpcaMBOCm2oa08upmw1Tug==/base.apk

Here is the more detailed log as requested:

2019-05-18 11:58:01.694 23217-23217/com.a**d.xyzapp.debug A/chromium: 

[FATAL:crashpad_client_linux.cc(404)] Render process (28925)'s crash wasn't handled by all associated  webviews, triggering application crash.
Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x7ab7b9d620 in tid 23217 (atientapp.debug), pid 23217 (atientapp.debug) (edited) 
like image 414
cooler Avatar asked May 17 '19 23:05

cooler


2 Answers

In your case Render process is crashing and it is not killed by the system.

So as described here, if you override

onRenderProcessGone(WebView view,
            RenderProcessGoneDetail detail)

above method then detail.didCrash() will holds true in your case. In that case, Renderer crashed because of an internal error, such as a memory access violation. The app itself crashes after detecting that the renderer crashed.

To handle the crash and allow your app to continue executing, you should follow the below steps:-

  1. Destroy the current WebView instance.
  2. Specify your business logic how your app can continue executing.
  3. Override onRenderProcessGone and return true.

Problem As soon as the OK button is tapped on the webview where our native app page would launch normally until a few weeks ago, the app crashes and we would be taken back to the start of the webview page asking us to enter the details.

This is because if a renderer crashes while loading a particular web page, attempting to load that same page again could cause a new WebView object to exhibit the same rendering crash behaviour.

Check code in this link for more info.

Hope this will help.

like image 145
Pravin Divraniya Avatar answered Sep 24 '22 08:09

Pravin Divraniya


Are you using mopub advertising platform? if so they have this bug associated with their sdk.
It is usually related to bug in web-page that is being tried to load.
There is also change in the way webview works from android 8.0 above. It is now multi-process based, which also gives you power to handle these kind of errors(renderer gone, out of memory and many others).
You should implement this override

public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)

More detail about this is here

Update: If you are using mopub or even webview, Android 9.0 blocks all non-https traffic. Consider using alternate way like mopub has implemented here.

like image 40
Vanshaj Daga Avatar answered Sep 23 '22 08:09

Vanshaj Daga