安卓漏洞 : WebViewCore fails with Assertion error

标签 android

不幸的是,我不能可靠地重现这个错误,但我很少得到它,偶尔它也会在实时崩溃日志中报告。这是用户使用 Droid 2.2.2 FRG83G

报告的堆栈跟踪
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertNull(Assert.java:233)
at junit.framework.Assert.assertNull(Assert.java:226)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:594)
at java.lang.Thread.run(Thread.java:1096)

这似乎是由于 WebViewCore.java 中的这一行造成的

Assert.assertNull(sWebCoreHandler);

android.os.Handler 的私有(private)静态实例 sWebCoreHandler 是不是 (感谢@Idolon 的更正) 已经初始化,但我不知道如何解决或防止此问题。

这种情况经常发生,足以让我担心。同样有趣的是,当应用程序正在加载甚至没有 WebView 的 Activity 时似乎会发生,尽管其中一个 Activity 确实有它。

附言这被归档为错误 # 16258

最佳答案

查看有罪的源代码...

public WebViewCore(Context context, WebView w, CallbackProxy proxy,
        Map<String, Object> javascriptInterfaces) {

    //....

    // We need to wait for the initial thread creation before sending
    // a message to the WebCore thread.
    // XXX: This is the only time the UI thread will wait for the WebCore
    // thread!
    synchronized (WebViewCore.class) {
        if (sWebCoreHandler == null) {
            // Create a global thread and start it.
            Thread t = new Thread(new WebCoreThread());

            //...

        }
    }

//...

private static Handler sWebCoreHandler;
// Class for providing Handler creation inside the WebCore thread.
private static class WebCoreThread implements Runnable {
    public void run() {
        Looper.prepare();
        Assert.assertNull(sWebCoreHandler); // this assertion fails
        synchronized (WebViewCore.class) {
            sWebCoreHandler = new Handler() {
        //...

这在任何WebView的构造函数中执行,断言错误来自WebCoreThread构造函数,它仅在sWebCoreHandler时被调用是空的,所以这个断言永远不会失败......理论上。除了它在 synchronized 子句之外和在 synchronized 子句内创建和启动的新线程内运行,据说只有一次。

您的错误似乎与同时创建 WebView 有关。如果您的应用程序只有一个 Activity 和一个 webview,请确保该 Activity 的调用频率不超过必要(=一次一个),WebView 是在 onCreate 方法而不是 Activity 构造函数中创建的,startActivity 是在主线程中调用,你应该没问题。

关于安卓漏洞 : WebViewCore fails with Assertion error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5734170/

相关文章:

java - import android.support 无法解析

java - 解析 -Android 获取多个推送通知

android - 未生成 RealmProxy 文件

android - 合并两个位图图像(并排)

android - 尝试使用数据库中的路径显示图像时出现java空指针异常

java - 可运行代码正在循环其操作

javascript - 英特尔 xdk 不适用于 android

android - 如何在Android中使用Robotium编写测试用例方法

android - Firebase 不创建新节点

android - 从 Android 设备访问本地主机