ClassNotFoundException and BIND_EXTERNAL_SERVICE and crash with Android WebView

Viewed 970

An extremely simple app, API level 24 (Android 7.0), trying to load a WebView in the only activity, on an actual physical device, gives the following in the log and stops the app:

I/cr_DRP: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp

and

W/System.err: java.lang.SecurityException: BIND_EXTERNAL_SERVICE failed, ComponentInfo{com.android.webview/org.chromium.content.app.SandboxedProcessService0} is not an externalService

and

A/chromium: [FATAL:jni_android.cc(233)] Check failed: false. Please include Java exception stack in crash report
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 6989 (Chrome_ProcessL)

What is going on? Some kind of version/dependency problems? How can it be corrected?

XML for WebView:

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

WebView code:

mWebView = findViewById(R.id.webview);
mWebView.loadUrl("https://google.com");

Full project: https://github.com/qabi/webviewtest

4 Answers

I was also facing similar issue with java.lang.SecurityException: BIND_EXTERNAL_SERVICE, in my case internet permission was missing in manifest.xml.

uses-permission android:name="android.permission.INTERNET"

having not yet enabled JavaScript appears to be a possible reason (it's disabled by default):

mWebView = findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("https://google.com");

First check the permission is given correctly in manifest.

uses-permission android:name="android.permission.INTERNET"

If this is included when we loading the url by default it try to redirect to chrome browser. I think this is causing the crash. Not sure anyway. Add following code to stop it.

 mWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url){                   
                    view.loadUrl(url);
                    return false; // then it is not handled by default action
           }
});

Webview object will be wv

   wv.setWebChromeClient(
            new WebChromeClient() {

                long mStartRX = TrafficStats.getTotalRxBytes();
                long mStartTX = TrafficStats.getTotalTxBytes();


                @Override
                public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                    Log.d("MyApplication", message + " -- From line "
                            + lineNumber + " of "
                            + sourceID);
                }

                @Override
                public void onProgressChanged(WebView view, int newProgress) {
                    super.onProgressChanged(view, newProgress);

                    long rxBytes = TrafficStats.getTotalRxBytes() - mStartRX;
                    long txBytes = TrafficStats.getTotalTxBytes() - mStartTX;

                    Log.d("TRAFFIC", "Current Bytes Rx ==>   " + rxBytes
                            + "   Bytes Tx ==>   " + txBytes
                            + " New progress ==> "  + newProgress);
                }
    });
   wv.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            pb.setVisibility(View.VISIBLE);

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            wv.loadUrl(url);
            return true;
        }



        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);


        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);


        }
    });
Related