Android WebView:网址加载后崩溃 [英] Android WebView: crash after url loading

查看:66
本文介绍了Android WebView:网址加载后崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的 webView 加载 url 时,应用程序在几秒钟后崩溃(没有错误日志...).

When loading an url with my webView, application crashes after few seconds (without error log...).

我的代码:

 wv = new WebView(this);
        wv.clearCache(true);
        wv.clearHistory();
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

        wv.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype, long contentLength) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setType(mimetype);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });


        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                // TODO change for other domains
                URL nextUrl;
                try {
                    nextUrl = new URL(url.toString());
                }catch (MalformedURLException e){
                    nextUrl = null;
                }

                if(nextUrl !=null && nextUrl.getHost().toString().equals(DOMAIN)) {
                    Toast.makeText(mContext, nextUrl.getHost().toString(), Toast.LENGTH_SHORT).show();
                    view.loadUrl(url);
                    return false;

                }else{
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(browserIntent);
                    return true;
                }

            }
        });

        wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                MainActivity.this.setProgress(progress * 1000);
            }
            public boolean onConsoleMessage(ConsoleMessage cm) {
                Log.d("MyProject: WebView: ", cm.message() + " -- From line "
                    + cm.lineNumber() + " of "
                    + cm.sourceId() );
            return true;
        }
        });

        wv.loadUrl(URL);
        setContentView(wv);

日志:

01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ "WebViewCoreThread" prio=5 tid=12 NATIVE
01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x419a0be0 self=0x68f6c750
01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ | sysTid=7288 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1773204176
01-20 18:00:50.799    7233-7288/ my.appli.com I/dalvikvm﹕ | state=R schedstat=( 0 0 0 ) utm=2326 stm=119 core=0
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #00  pc 000012a0  /system/lib/libcorkscrew.so (unwind_backtrace_thread+27)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #01  pc 0006235c  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #02  pc 000561bc  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+303)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #03  pc 00056256  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #04  pc 000478c8  /system/lib/libdvm.so (dvmDebuggerSignalHandler(int, siginfo*, void*)+15)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.fireSharedTimer(JWebCoreJavaBridge.java:92)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:108)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.os.Looper.loop(Looper.java:137)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:900)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at java.lang.Thread.run(Thread.java:856)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ [ 01-20 18:00:50.841  7233: 7288 F/libc     ]
    Fatal signal 11 (SIGSEGV) at 0x0000001c (code=1), thread 7288 (WebViewCoreThre)

我在尝试使用我的 android 设备 (4.1) 的默认浏览器加载相同的 URL 时遇到了同样的问题(崩溃).

I've experienced the same issue(crash) when trying to load the same URL with the default browser of my android device(4.1).

我要加载的网址是:

http://presentbox.jp

感谢您的帮助.

--- 编辑 1

我用最近的 Android 手机 (4.4) 尝试过,应用程序没有崩溃.

I' ve tried with a recent android phone (4.4) and application didn't crashed.

出于调试目的,我删除了网站的所有重要部分(图片、js 等),但向下滚动后应用程序仍然崩溃.

For debug purpose, I've deleted all heavy parts of my website (images, js,...) but application still crash after scrolling down.

推荐答案

//编辑:找到了!general.css 中第 2540 行的罪魁祸首:

// Edit: Found it! The culprit in on line 2540 in general.css:

#head-search-form{display: block;margin: 30px 0;}

更具体地说,它是 display: block 以某种方式使 WebView 窒息.我不是一个 Web 开发人员,但是用 flexnone 交换值似乎不再导致崩溃(我无法分辨视觉差异在移动设备上).希望有帮助!

More specifically, it's display: block that somehow makes the WebView choke. I'm not much of a web developer, but exchanging the value with flex or none seems to no longer result in a crash (and I couldn't tell the visual difference on a mobile device). Hope that helps!

我已经建立了一个小型测试项目,并且能够在(虚拟)Android 4.1 设备上重现崩溃.它似乎只在页面完全加载后滚动时发生.IE.您可以毫无问题地展开菜单抽屉,只要您不开始滚动...

I've set up a small test project and have been able to reproduce the crash on a (virtual) Android 4.1 device. It only seems to happens upon scrolling, after the page has fully loaded. I.e. you can expand the menu drawer without any issues, as long as you don't start scrolling...

我能够将罪魁祸首缩小到 general.css.只要您不加载该样式表,页面就会正常工作并且可以很好地滚动,但当然看起来不会很漂亮.

I was able to narrow down the culprit to general.css. As soon as you don't load that style sheet, the page will work and scroll just fine, but of course won't look very pretty.

由于 general.css 有 3300 多行,我建议您通过修复 W3C CSS 验证器指示的错误.如果这不能解决问题,请开始禁用与照片网格相关的样式规则,尤其是涉及动画/转换的任何内容.如果我能找到时间,我自己也可以尝试一下.

Since general.css counts 3300+ lines, I'd suggest you start your search for the actual cause by fixing the errors indicated by the W3C CSS Validator. If that doesn't solve the issue, start disabling style rules related to the photo grid, especially anything that involves animation/transformation. If I can find the time, I may have a go at this myself too.

这里有一个更广泛的堆栈跟踪,仅供参考.其他人也可以在那里找到更多的指针.

Just for your information, here's a more extensive stack trace. Someone else may be able to find some more pointers in there too.

mh.test.webview A/libc: Fatal signal 11 (SIGSEGV) at 0x00001f08 (code=1), thread 11949 (WebViewCoreThre)
I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG: Build fingerprint: 'generic/vbox86p/vbox86p:4.1.1/JRO03S/eng.buildbot.20151117.133415:userdebug/test-keys'
I/DEBUG: pid: 11930, tid: 11949, name: WebViewCoreThre  >>> mh.test.webview <<<
I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00001f08
I/DEBUG:     eax b84902e4  ebx 9ba8b488  ecx b804b028  edx b83c0224
I/DEBUG:     esi b8490360  edi b804b028
I/DEBUG:     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b
I/DEBUG:     eip 00001f08  ebp 997b9748  esp 997b96dc  flags 00010296
I/DEBUG:     #00  pc 00001f08  <unknown>
I/DEBUG:     #01  pc 00344fd6  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+38)
I/DEBUG:     #02  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #03  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #04  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #05  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #06  pc 00346c55  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::updateCompositingLayers(WebCore::CompositingUpdateType, WebCore::RenderLayer*)+213)
I/DEBUG:     #07  pc 0020e727  /system/lib/libwebcore.so (WebCore::FrameView::layout(bool)+1159)
I/DEBUG:     #08  pc 0068126f  /system/lib/libwebcore.so (WebCore::Document::updateLayout()+127)
I/DEBUG:     #09  pc 0068bbda  /system/lib/libwebcore.so (WebCore::Document::updateLayoutIgnorePendingStylesheets()+90)
I/DEBUG:     #10  pc 005ead53  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue(int, WebCore::EUpdateLayout) const+467)
I/DEBUG:     #11  pc 005f35e9  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue(int) const+41)
I/DEBUG:     #12  pc 005e68d7  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyValue(int) const+55)
I/DEBUG:     #13  pc 006297f8  /system/lib/libwebcore.so (WebCore::CSSStyleDeclaration::getPropertyValue(WTF::String const&)+88)
I/DEBUG:     #14  pc 004d9475  /system/lib/libwebcore.so (WebCore::CSSStyleDeclarationInternal::getPropertyValueCallback(v8::Arguments const&)+181)
I/DEBUG:     #15  pc 000efdd4  <unknown>
I/DEBUG:     #16  pc 0005cf6b  <unknown>
I/DEBUG:     #17  pc 000bb32f  <unknown>
I/DEBUG:     #18  pc 00003b41  <unknown>
I/DEBUG:     #19  pc 000f47ce  <unknown>
I/DEBUG:     #20  pc 0001a5a3  <unknown>
I/DEBUG:     #21  pc 000065e3  <unknown>
I/DEBUG:     #22  pc 00003b41  <unknown>
I/DEBUG:     #23  pc 00024c59  <unknown>
I/DEBUG:     #24  pc 00024dad  <unknown>
I/DEBUG:     #25  pc 00003b41  <unknown>
I/DEBUG:     #26  pc 0001a59c  <unknown>
I/DEBUG:     #27  pc 000d7172  <unknown>
I/DEBUG:     #28  pc 0001a5a3  <unknown>
I/DEBUG:     #29  pc 000d40ed  <unknown>
I/DEBUG:     #30  pc 00017bf9  <unknown>
I/DEBUG:     #31  pc 00008c2a  <unknown>
I/DEBUG:          997b969c  00000000  
I/DEBUG:          997b96a0  00000000  
I/DEBUG:          997b96a4  00000000  
I/DEBUG:          997b96a8  00000000  
I/DEBUG:          997b96ac  00000000  
I/DEBUG:          997b96b0  00000000  
I/DEBUG:          997b96b4  00000000  
I/DEBUG:          997b96b8  00000000  
I/DEBUG:          997b96bc  00000000  
I/DEBUG:          997b96c0  00000000  
I/DEBUG:          997b96c4  00000000  
I/DEBUG:          997b96c8  00000000  
I/DEBUG:          997b96cc  00000000  
I/DEBUG:          997b96d0  00000000  
I/DEBUG:          997b96d4  00000000  
I/DEBUG:          997b96d8  00000000  
I/DEBUG:     #00  997b96dc  9ad1cdd4  /system/lib/libwebcore.so (WebCore::RenderLayer::updateLayerPosition()+52)
I/DEBUG:          997b96e0  b84902e4  [heap]
I/DEBUG:          997b96e4  b8490090  [heap]
I/DEBUG:          997b96e8  0000000f  
I/DEBUG:          997b96ec  0000002f  
I/DEBUG:          997b96f0  b8490090  [heap]
I/DEBUG:          997b96f4  00000001  
I/DEBUG:          997b96f8  9ad2204e  /system/lib/libwebcore.so (WebCore::RenderLayer::repaintIncludingNonCompositingDescendants(WebCore::RenderBoxModelObject*)+14)
I/DEBUG:          997b96fc  b827f428  [heap]
I/DEBUG:          997b9700  9ba8b488  /system/lib/libwebcore.so
I/DEBUG:          997b9704  b8490090  [heap]
I/DEBUG:          997b9708  997b9748  [stack:11949]
I/DEBUG:          997b970c  9ad35d38  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::updateBacking(WebCore::RenderLayer*, WebCore::RenderLayerCompositor::CompositingChangeRepaint)+344)
I/DEBUG:          997b9710  b8490014  [heap]
I/DEBUG:          997b9714  b848fe3c  [heap]
I/DEBUG:          997b9718  00000012  
I/DEBUG:          ........  ........
I/DEBUG:     #01  997b9750  b8490360  [heap]
I/DEBUG:          997b9754  b8490090  [heap]
I/DEBUG:          997b9758  00000000  
I/DEBUG:          997b975c  997b98e0  [stack:11949]
I/DEBUG:          997b9760  997ba84f  [stack:11949]
I/DEBUG:          997b9764  b843a9e4  [heap]
I/DEBUG:          997b9768  00000034  
I/DEBUG:          997b976c  00000180  
I/DEBUG:          997b9770  b848fe3c  [heap]
I/DEBUG:          997b9774  b85257f8  [heap]
I/DEBUG:          997b9778  9ace0300  /system/lib/libwebcore.so (WebCore::RenderBox::dirtyLineBoxes(bool)+80)
I/DEBUG:          997b977c  43400000  
I/DEBUG:          997b9780  b83fe51c  [heap]
I/DEBUG:          997b9784  997b9788  [stack:11949]
I/DEBUG:          997b9788  004a0000  
I/DEBUG:          997b978c  b848feb8  [heap]
I/DEBUG:          ........  ........
I/DEBUG:     #02  997b9aa0  b804b028  [heap]
I/DEBUG:          997b9aa4  b8490360  [heap]
I/DEBUG:          997b9aa8  00000000  
I/DEBUG:          997b9aac  997b9c30  [stack:11949]
I/DEBUG:          997b9ab0  997ba84f  [stack:11949]
I/DEBUG:          997b9ab4  b83fe51c  [heap]
I/DEBUG:          997b9ab8  00000000  
I/DEBUG:          997b9abc  00000001  
I/DEBUG:          997b9ac0  b86fd038  [heap]
I/DEBUG:          997b9ac4  b86fd368  [heap]
I/DEBUG:          997b9ac8  997b9b48  [stack:11949]
I/DEBUG:          997b9acc  9adac54a  /system/lib/libwebcore.so (WebCore::TransformState::move(int, int, WebCore::TransformState::TransformAccumulation)+58)
I/DEBUG:          997b9ad0  b83fe678  [heap]
I/DEBUG:          997b9ad4  b8294d4c  [heap]
I/DEBUG:          997b9ad8  00580b05  
I/DEBUG:          997b9adc  b83fe770  [heap]
I/DEBUG:          ........  ........
I/DEBUG:     (no map below)
I/DEBUG:     (no map for address)
I/DEBUG:     20c1e000-20c1f000 

这篇关于Android WebView:网址加载后崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆