delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 576 forks source link

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/SafeBrowsingResponse #202

Open asad1492 opened 6 years ago

asad1492 commented 6 years ago

I am facing this exception

"java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/SafeBrowsingResponse" while implementing webview in android.

I have searched for an appropriate solution over the web but didn't find anything useful.]

My XML file is this

` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar_title" />

    <im.delight.android.webview.AdvancedWebView
        android:id="@+id/mWebview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

`

And my java code against this XML is

`public class PaymentActivity extends ParentActivity implements AdvancedWebView.Listener {

// private WebView webView;

private AdvancedWebView mWebView; ProgressDialog dialog; UserModel userModel; SessionManager sessionManager;

@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_payment);

ButterKnife.bind(this);
setActionBar("Payment");
sessionManager = new SessionManager(this);
userModel = sessionManager.getUserInformation();

mWebView = findViewById(R.id.mWebview);
mWebView.setListener(this, this);
mWebView.getSettings().setJavaScriptEnabled(true);

String planType = getIntent().getStringExtra("planType");

String url = "www.google.com";

dialog = new ProgressDialog(this);
dialog.setMessage("Loading");
dialog.setCancelable(false);

mWebView.loadUrl(url);

}

@Override public void onPageStarted(String url, Bitmap favicon) {

dialog.show();

}

@Override public void onPageFinished(String url) { dialog.dismiss(); }

@Override public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {

}

@Override public void onExternalPageRequest(String url) {

}

@Override public void onPageError(int errorCode, String description, String failingUrl) {

}`

My compileSdkVersion is 26, minSdkVersion is 17 and targetSdkVersion is 22. I am testing this code on Android 8.0 API 26.

Any help in this regard will be highly appreciated.

ocram commented 6 years ago

Does this in fact make your application crash? Or is it simply logged as a warning?

If you add the following code during (or right after) initialization of your WebView, does the problem disappear?

if (Build.VERSION.SDK_INT >= 26) {
    myWebView.getSettings().setSafeBrowsingEnabled(false);
}
asad1492 commented 6 years ago

No it's not crashing the application. It's just throwing an exception as warning in the log. And the activity is showing a blank screen. I have changed my code like this but didn't get the success. It's still the same.

mWebView = findViewById(R.id.mWebview); if (Build.VERSION.SDK_INT >= 26) { mWebView.getSettings().setSafeBrowsingEnabled(false); } mWebView.setListener(this, this); mWebView.getSettings().setJavaScriptEnabled(true);

lumeshadow commented 6 years ago

I am having the same issue. Also getting a warning stack trace and a blank webview in stead of my content. Any advice would be greatly appreciated.

asad1492 commented 6 years ago

I didn't find any solution to this problem. So I have now switched to Chrome Custom Tabs. It's way much better than webview. And it's very easy to implement. Have a look at this https://github.com/codepath/android_guides/wiki/Chrome-Custom-Tabs

lumeshadow commented 6 years ago

This looks interesting but won't help me because I am coding an app that has to work on a custom build of android (AOSP Lollipop) that does not have ANY google content. Chrome cannot be installed. It is quite frustrating.

asad1492 commented 6 years ago

Oh I see. Best of luck

lumeshadow commented 6 years ago

I think my problem is based on the fact that I have a local webserver serving content to my app. These requests are done with http, not https. And there is now a requirement for safe browsing in the webview component so https requests might do the trick. Looking into making my server secure.

ocram commented 6 years ago

Well, Chrome Custom Tabs are certainly better for some use cases, and worse for several other use cases. WebView and Chrome Custom Tabs serve different needs and use cases. The more important web content is within your application, the more likely you’ll generally be to want WebView.

Regarding this issue here, the android.webkit.SafeBrowsingResponse is added in Android API level 27, so it’s obvious why it cannot be found on API level 26. The question is why the WebView requests and attempts to find that class.

Disabling “Safe Browsing” programmatically was one idea. Another idea might be disabling it in your manifest:

<manifest>
    <application>
        <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing" android:value="false" />
    </application>
</manifest>

If that doesn’t work, the question remains why WebView attempts to do something with “Safe Browsing” although that feature is disabled.

ghost commented 5 years ago

Is this problem solved? I am facing same issue and this one is most similar. I have tried setting safeBrowsing false too , but still my webview sometime loads the local file file:///location/index.html and sometimes goes blank. However, whenever it is blank Failed resolution of: Landroid/webkit/TracingController appears in logcat.

I am wondering why is this issue still open for last 8 months

ocram commented 5 years ago

As you can see above, two solutions have been suggested but there is not enough feedback to tell whether this issue has been resolved or not.

In general, you’d need to test this on different devices with different Android versions to see where the problem actually occurs.

If the two solutions above don’t work, it’s most likely to be a bug in the built-in WebView implementation of the OS. There may even be some bug report on Android or Chrome’s issue tracker.

unclebu001 commented 5 years ago

the two solutions above don’t work.what else solution can you suggest?