Android WebView 已开始在 Android 9 上崩溃

标签 android webview crash android-9.0-pie

你好专家 Android 开发者:

我们有一个安卓应用,我们的基本工作流程如下

  1. 通过电子邮件或短信向用户发送链接
  2. 用户点击链接并在 Chrome 或 Android 默认浏览器上打开一个页面,并有一个名为JOIN
  3. 的按钮
  4. 用户点击此JOIN 按钮,我们的应用启动并在 webview 中显示一个页面,要求用户输入名字、姓氏和电话/电子邮件,然后用户点击名为INITIATE
  5. 的按钮
  6. 我们验证信息 - 如果用户是新用户,我们创建一个记录,如果用户存在,我们更新它等等,然后显示一个弹出窗口,通知他的 session 将被记录。
  7. 只要用户在弹出窗口中单击“确定”,然后控件就会存在 webview 并且用户位于 native android 页面上。

问题 一旦在几周前我们的原生应用程序页面正常启动的 webview 上点击 OK 按钮,应用程序就会崩溃,我们将被带回到 webview 页面的开头,要求我们输入详细信息。

请注意以下注意事项:

  • 首先,这仅发生在 Android 9 的情况下。我们已经在 Samsung Galaxy S8 和 S9 上对此进行了测试。它不是每次都发生,而是经常发生,我什至说有时 3 次中有 2 次。在最好的时候,10 次中有 2 次发生了,但它确实发生了。
  • 这段代码在过去 1 年左右的时间里一直在成功运行,我们从未遇到过这个问题。它在过去 3-4 周才开始发生。
  • 我们还有一个 iOS 应用,没有发现同样的问题。

这是一个可能有帮助的代码 fragment - 这就是我们加载 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()

=======我们这里重写了很多方法后面跟着

webview.setWebViewClient(new WebViewClient()

=======我们在这里覆盖方法。

知道会发生什么吗?我们尝试在通过 USB 模式调试时查看日志,但除了 Android 控制台上显示的内容外,我们在日志中看不到太多内容,如下所示:

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

回溯:

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

根据要求,这里是更详细的日志:

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) 

最佳答案

在你的情况下,渲染进程正在崩溃,但它没有被系统杀死。

如前所述here , 如果你覆盖

onRenderProcessGone(WebView view,
            RenderProcessGoneDetail detail)

上面的方法然后 detail.didCrash() 将在您的情况下保持 true。在那种情况下,渲染器会因为内存访问冲突等内部错误而崩溃。在检测到渲染器崩溃后,应用程序本身崩溃。

要处理崩溃并让您的应用继续执行,您应该按照以下步骤操作:-

  1. 销毁当前的 WebView 实例。
  2. 指定您的业务逻辑,您的应用将如何继续执行。
  3. 重写 onRenderProcessGone 并返回 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.

这是因为如果渲染器在加载特定网页时崩溃,尝试再次加载同一页面可能会导致新的 WebView 对象表现出相同的渲染崩溃行为。

检查 this link 中的代码了解更多信息。

希望这会有所帮助。

关于Android WebView 已开始在 Android 9 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56194727/

相关文章:

android - 在Android Eclipse中获取错误 “No resource found that matches the given name (at ' value'和值 '@integer/google_play_services_version')”

Android ActionBar.Tab setCustomView() 不 fill_parent

java - Android:下载文件八位字节流 WebView

javascript - 防止网站在 WebView 中加载并在浏览器中打开

swift - 在命令行中使用 WebView : found nil error while unwrapping

android - 我应该创建单独的 Activity 来检查用户是否登录?

android - 在 Android 布局设计中使用特殊符号 (<, >)

android - Games.Players.getCurrentPlayer崩溃

ios - 在单元测试用例 (RestKit) 之间重置持久性存储的零星崩溃

android - 使用 proguard Android 后数据库崩溃