本文介绍: 具体报错:2021-12-21 08:41:54.489 19437-19437/com.maniu.mn_vip_webview E/AndroidRuntime: FATAL EXCEPTION: main Process: com.maniu.mn_vip_webview:remoteweb, PID: 19437 java.lang.RuntimeException: Unable to create application com.maniu.mn_vip_webview.Bas

具体报错

2021-12-21 08:41:54.489 19437-19437/com.maniu.mn_vip_webview E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.maniu.mn_vip_webview:remoteweb, PID: 19437
    java.lang.RuntimeException: Unable to create application com.maniu.mn_vip_webview.BaseApplication: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Lock owner com.maniu.mn_vip_webview (pid 19339)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7367)
        at android.app.ActivityThread.access$2400(ActivityThread.java:308)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8349)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Lock owner com.maniu.mn_vip_webview (pid 19339)
        

原因是 Android P针对 WebView在不同进程无法访问自己进程中的webview目录
解决办法
原来的代码

public class BaseApplication extends Application {
    public static WebView webView;

    @Override
    public void onCreate() {
        super.onCreate();
        
        webView = new WebView(this);
        webView.addJavascriptInterface(this,"android");//添加js监听 这样html就能调用客户端
       ... ...
    }

需要在 webView = new WebView(this); 前面一个判断

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
   	String processName = getProcessName();
    WebView.setDataDirectorySuffix(processName);
}

更改后的代码

public class BaseApplication extends Application {
    public static WebView webView;

    @Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName();
            WebView.setDataDirectorySuffix(processName);
        }
        webView = new WebView(this);
        webView.addJavascriptInterface(this,"android");//添加js监听 这样html就能调用客户端
        ... ...

原文地址:https://blog.csdn.net/Redmoon955331/article/details/122054490

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_16511.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注