owned this note changed 6 years ago
Linked with GitHub

如何逃離難解的 Crash 地獄:以 WebView 為例 - 林容瑋

歡迎來到 MOPCON 2019 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

共筆入口:https://hackmd.io/@mopcon/2019
手機版請點選上方 按鈕展開議程列表。

會場 wifi-SSID: mopcon-2019
會場 wifi-PASSWD: mopcon-2019

tags: MOPCON 2019

從這開始

Our culture (講者的公司文化)

  • Performance driven
    • Crash, ANR, Cold start, rendering speed, memory
  • Move fast
  • Love to share
    • Educate
    • Document

Crash Type

  • NO messages, and unsolveable
  • Ambiguous messages and solvable
    • 比如 out memory error,就可以從 application 中看是不是呼叫了比較大量的 function。
  • Ambiguous messages, unpredictable, but solvable
    • 使用 Catch exception 的方式來解決這問題。

Catch Exception

  • Main thread -> ActivityThread.main()
  • Intercept handleMessage -> 使用 try-catch 來抓住 exception。

Hook Callback

  • 當我們藉由 try-catch 的 catch 中取得 exception,我們可以忽略該 exception 或是針對該 excetpion 來進行特定的處理。

When to hook

  • 一般在 onCreate 的時候就掛上去

Caveat

  • The solution is unstable because it relies on the name and type of the field, Google can change it in any future version.
  • If we overuse it, we may overlook some big problems.
  • Mainly focus on mrain handler

Recap - Handler

  • Implement custom Handler callback
  • Implement method to hook callback onto the Handler with reflection

Recap -Looper

  • Runnable for intercepti

What's more

  • 針對 WebViewClient.onRenderProcessGone (Android 8 或更新版本)。這部分有提供專門的 method 來去應對這樣的問題。
  • Not all WebView client in APP will override the callback
  • Use Transform API to implement the callback for them
    • Get the code within directories and jar
    • Filter out WebView without onRenderProcessGone
    • Javassist, ASM
Select a repo