【问题标题】:java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/SafeBrowsingResponsejava.lang.NoClassDefFoundError:解析失败:Landroid/webkit/SafeBrowsingResponse
【发布时间】:2018-12-25 03:52:46
【问题描述】:

我正面临这个异常

"java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/SafeBrowsingResponse" 在 android 中实现 webview 时。

我在网上搜索了合适的解决方案,但没有找到任何有用的东西。

我的 XML 文件是这个

    <?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>

</RelativeLayout>

我针对这个 XML 的 java 代码是

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) {

}

我的 compileSdkVersion 是 26,minSdkVersion 是 17,targetSdkVersion 是 22。我正在Android 8.0 API 26 上测试此代码。

我们将非常感谢您在这方面的任何帮助。

【问题讨论】:

  • 也许如果你能提供更多关于你在哪里以及如何使用它的上下文,你可能会得到答案。我今天早些时候遇到了同样的问题,我正在测试 API 22。我的问题不是 SafeBrowsingResponse 类,而是传递了错误的文件路径(我使用本地文件进行了测试)。

标签: java android android-layout webview


【解决方案1】:

根据documentation,这个类是在Android 27级添加的。您正在尝试在26级测试平台上使用它。自然,平台无法加载它不知道的类。

【讨论】:

  • 有什么方法可以在 API 26 或更低版本上使用它?
  • 简单的搜索并没有让我提到这个类的反向移植,所以我认为答案是否定的。
  • "你正在使用它..." 该应用程序不直接使用该方法,但它调用 webview/webkit,而后者又调用该方法。这是否表明 webkit 本身正在使用磨损级别的 API?
猜你喜欢
  • 2022-08-03
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
相关资源
最近更新 更多