java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377
at jO.b(PG:102)
at jO.b(PG:182)
at jO.a(PG:163)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.a(PG:234)
at com.android.webview.chromium.WebViewChromium.init(PG:44)
at android.webkit.WebView.<init>(WebView.java:683)
at android.webkit.WebView.<init>(WebView.java:609)
at android.webkit.WebView.<init>(WebView.java:592)
bug 参考:https://bugs.chromium.org/p/chromium/issues/detail?id=558377
解决思路主要是为每个进程设置自己的目录。
但亿级app上,依然会存在崩溃的场景。
主要是无法准确判断是否处于主进程,只能逐级堵住漏洞
if (Build.VERSION.SDK_INT >= 28 && !ApplicationContext.mIsHostPorcess) {
try {
String processName = BaseContext.getCurrentProcessName(activity.getApplication());
if (StringUtils.isEmpty(processName)) {
DebugLog.ppLogBuffer.log(TAG, "D", "initDataDirectorySuffix getCurrentProcessName is null!");
return;
}
WebView.setDataDirectorySuffix(processName);
DebugLog.log(TAG, "QYWebviewCorePanel setDataDirectorySuffix" + processName);
} catch (Exception e) {
DebugLog.ppLogBuffer.log(TAG, "D", "initDataDirectorySuffix execption caught:"+ e.toString());
}
}
核心问题在于ApplicationContext.mIsHostPorcess 是否能够判断准确
更新解决思路
Android 11 以后官方已经修复。
重点解决的 Android 9,10 两个版本的崩溃问题,解决思路是new webveiw 时,将 SDK 版本手动改成8,new webview 后,再将其改回。 这样可以绕过这个崩溃问题。
具体思路 通过ASM插桩(最近gradle已集成):
new webview() 前:
context.getApplicationInfo().targetSdkVersion = Build.VERSION_CODES.O;
new webview() 后:
context.getApplicationInfo().targetSdkVersion = 原 VERSION_CODES;