我编写了一个应用程序,它在Webview中显示html页面,这些页面在ViewPager中管理。一切正常,但是当我从一个页面滑动到另一个页面时,我有一些ANR。 ANR数据转储显示主线程已通过ThreadedRenderer.nSyncAndDrawFrame()调用,该方法调用本机方法,该方法显然与呈现器线程通信,并等待该线程完成绘制视图。由于这两者都在执行本机代码,因此很难弄清楚正在进行的操作,但似乎Renderer线程从未表示主线程要恢复,因此导致ANR。在ANR报告之前,logcat中没有任何内容表明存在任何问题。
有没有人建议如何解决这个问题?我假设对ThreadedRenderer.nSyncAndDrawFrame()的调用与Webview相关联,但我实际上没有任何东西可以确认。
问题是不可重复的,因为如果我重新启动应用程序并导航到ANR发生时显示的同一页面,它就不会再次发生。 Device是运行Android 5.1的Nexus 7.
主要和渲染器线程的ANR堆栈跟踪:
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 obj=0x73547000 self=0xb4827800
| sysTid=1248 nice=-6 cgrp=default sched=0/0 handle=0xb6fd6bec
| state=S schedstat=( 0 0 0 ) utm=6035 stm=1406 core=0 HZ=100
| stack=0xbe5a6000-0xbe5a8000 stackSize=8MB
| held mutexes=
kernel: (couldn't read /proc/self/task/1248/stack)
native: #00 pc 000133b8 /system/lib/libc.so (syscall+28)
native: #01 pc 00016a81 /system/lib/libc.so (__pthread_cond_timedwait_relative(pthread_cond_t*, pthread_mutex_t*, timespec const*)+56)
native: #02 pc 0003c73b /system/lib/libhwui.so (???)
native: #03 pc 0003c771 /system/lib/libhwui.so (???)
native: #04 pc 0083fd83 /data/dalvik-cache/arm/system@framework@boot.oat (Java_android_view_ThreadedRenderer_nSyncAndDrawFrame__JJJF+134)
at android.view.ThreadedRenderer.nSyncAndDrawFrame(Native method)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:340)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke!(Native method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
"RenderThread" prio=5 tid=26 Native
| group="main" sCount=1 dsCount=0 obj=0x12c07820 self=0xa1c30800
| sysTid=1303 nice=-4 cgrp=default sched=0/0 handle=0xa1c44c00
| state=S schedstat=( 0 0 0 ) utm=8314 stm=1817 core=0 HZ=100
| stack=0xa0cc2000-0xa0cc4000 stackSize=1012KB
| held mutexes=
kernel: (couldn't read /proc/self/task/1303/stack)
native: #00 pc 000133b8 /system/lib/libc.so (syscall+28)
native: #01 pc 0001741b /system/lib/libc.so (__futex_wait_ex+42)
native: #02 pc 00017761 /system/lib/libc.so (pthread_mutex_lock+230)
native: #03 pc 0001d767 /system/vendor/lib/libgsl.so (os_mutex_lock+6)
native: #04 pc 0001ea88 /system/vendor/lib/egl/libEGL_adreno.so (egliDoDestroyEGLImage+180)
native: #05 pc 0008698d /system/vendor/lib/egl/libGLESv2_adreno.so (rb_image_try_release+32)
native: #06 pc 00086acf /system/vendor/lib/egl/libGLESv2_adreno.so (rb_destroy_resource_updates_pure+136)
native: #07 pc 00085491 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_perform_resolve+276)
native: #08 pc 00085761 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_resolve+464)
native: #09 pc 0008a891 /system/vendor/lib/egl/libGLESv2_adreno.so (rb_surface_swap+228)
native: #10 pc 0006af89 /system/vendor/lib/egl/libGLESv2_adreno.so (gl2_surface_swap+76)
native: #11 pc 0005d12b /system/vendor/lib/egl/libGLESv2_adreno.so (oglSwapBuffer+194)
native: #12 pc 00013ddc /system/vendor/lib/egl/libEGL_adreno.so (qeglDrvAPI_eglSwapBuffers+1776)
native: #13 pc 00007b60 /system/vendor/lib/egl/libEGL_adreno.so (eglSwapBuffers+16)
native: #14 pc 0001237f /system/lib/libEGL.so (eglSwapBuffers+290)
native: #15 pc 0003d291 /system/lib/libhwui.so (???)
native: #16 pc 0003bd05 /system/lib/libhwui.so (???)
native: #17 pc 0003beb5 /system/lib/libhwui.so (???)
native: #18 pc 0003caed /system/lib/libhwui.so (???)
native: #19 pc 0003e743 /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+66)
native: #20 pc 000104d5 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+112)
native: #21 pc 0005f839 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+72)
native: #22 pc 00010045 /system/lib/libutils.so (???)
native: #23 pc 00016baf /system/lib/libc.so (__pthread_start(void*)+30)
native: #24 pc 00014af3 /system/lib/libc.so (__start_thread+6)
答案 0 :(得分:2)
我也面临这个问题似乎是Chromium bug,这与最新的Chromium Webview 43.0.23567.121有关。您可以尝试在应用上回滚webview并再次检查。对我来说,只能在最新的Webview版本上重现。
答案 1 :(得分:2)
这可能是Android 7.0 WebView上的一个错误,您可以通过以下两种方式修复它:
1,webView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
2,机器人:硬件加速="假"
答案 2 :(得分:0)
这可能是driver
和chromium
错误,请参阅
https://bugs.chromium.org/p/chromium/issues/detail?id=501901