Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview causes ANR

I have written an app which displays html pages in Webviews, which are managed in a ViewPager. All working ok, but I have had a few ANRs when swiping from one page to another. The ANR data dump shows that the main thread has called through ThreadedRenderer.nSyncAndDrawFrame() which calls a native method, which apparently communicates with the Renderer thread, and waits for that thread to complete drawing the view. Since both of these are executing native code it's hard to work out what's going on but it appears the Renderer thread has never signalled the main thread to resume, hence causing the ANR. There is nothing in the logcat prior to the ANR report that suggests any problem.

Does anyone have suggestions for how to troubleshoot this? I am assuming that the call to ThreadedRenderer.nSyncAndDrawFrame() is associated with the Webview, but I don't actually have anything to confirm that.

The problem is not repeatable, in the sense that if I restart the app and navigate to the same page that was showing when the ANR occurred, it doesn't happen again. Device is a Nexus 7 running Android 5.1.

ANR stacktrace for main and renderer threads:

"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@[email protected] (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)
like image 352
Clyde Avatar asked Jun 14 '15 11:06

Clyde


People also ask

What is WebView used for?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

Is WebView deprecated in Android?

This interface was deprecated in API level 12. This interface is now obsolete.


2 Answers

It may be a bug on Android 7.0 WebView, you can fix it by two ways below:

1、webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

2、android:hardwareAccelerated="false"

like image 169
hiphonezhu Avatar answered Oct 19 '22 23:10

hiphonezhu


I faced with this issue too Seems that Chromium bug, that is related with latest Chromium Webview 43.0.23567.121. You could try to rollback webview on your app and check it again. For me issue reproducable only at latest Webview version.

like image 24
Andrey T Avatar answered Oct 20 '22 00:10

Andrey T