问题
I have an activity with a ViewPager and TabLayout as below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="@+id/item_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/item_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/item_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/item_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
One of the Fragments is a WebView. In order to have the Toolbar hide when the WebView is scrolled, I have the WebView in a NestedScrollView.
Prior to adding the NestedScrollView, the app worked fine, but it didn't hide the Toolbar.
Now, as soon as the WebView finished loading, the app closes without a Java stack trace.
The Fragment layout is below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/browser_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/browser_loading_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="@color/colorAccent"
android:layout_gravity="center"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<WebView
android:id="@+id/browser_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
</WebView>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
When something is to be loaded, mWebView.loadUrl is called. The WebView has a client so that when the page load is finished the Spinner visibility is set to gone and the WebView is made visible.
The Android Monitor reads :
10-25 15:22:12.111 3871-3871/com.tpb.hn I/Browser: loadURL: WebView loading
10-25 15:22:12.113 3871-3871/com.tpb.hn I/cr_Ime: ImeThread is not enabled.
10-25 15:22:12.118 3871-3911/com.tpb.hn I/OpenGLRenderer: Initialized EGL, version 1.4
10-25 15:22:12.118 3871-3911/com.tpb.hn D/OpenGLRenderer: Swap behavior 1
[ 10-25 15:22:12.118 3871: 3911 D/ ]
HostConnection::get() New Host Connection established 0x7ffeeca88c00, tid 3911
10-25 15:22:12.126 3871-3936/com.tpb.hn E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
10-25 15:22:12.136 3871-3936/com.tpb.hn I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
[ 10-25 15:22:12.138 3871: 3936 D/ ]
HostConnection::get() New Host Connection established 0x7ffeeb7fe080, tid 3936
10-25 15:22:12.219 3871-3871/com.tpb.hn W/chromium: [WARNING:shell.cc(299)] Instance: exe:chrome attempting to register an instance for a process it created for target: exe:chrome_renderer without the mojo:shell{client_process} capability class.
10-25 15:22:12.317 3871-3871/com.tpb.hn W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 3871
10-25 15:22:12.317 3871-3871/com.tpb.hn D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: false
10-25 15:22:12.418 3871-3876/com.tpb.hn I/art: Do partial code cache collection, code=24KB, data=29KB
10-25 15:22:12.419 3871-3876/com.tpb.hn I/art: After code cache collection, code=24KB, data=29KB
10-25 15:22:12.419 3871-3876/com.tpb.hn I/art: Increasing code cache capacity to 128KB
10-25 15:22:12.635 3871-3871/com.tpb.hn I/HNLoader: onResponse: [I@842b545
10-25 15:22:12.635 3871-3871/com.tpb.hn I/ContentAdapter: IdLoadDone:
10-25 15:22:13.673 3871-3876/com.tpb.hn I/art: Do partial code cache collection, code=55KB, data=61KB
10-25 15:22:13.673 3871-3876/com.tpb.hn I/art: After code cache collection, code=55KB, data=61KB
10-25 15:22:13.673 3871-3876/com.tpb.hn I/art: Increasing code cache capacity to 256KB
10-25 15:22:13.765 3871-3871/com.tpb.hn W/art: Attempt to remove non-JNI local reference, dumping thread
10-25 15:22:13.766 3871-3911/com.tpb.hn E/OpenGLRenderer: GL error: GL_INVALID_VALUE
10-25 15:22:13.766 3871-3911/com.tpb.hn A/OpenGLRenderer: GL errors! frameworks/base/libs/hwui/BakedOpRenderer.cpp:66
--------- beginning of crash
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: Chrome build fingerprint:
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: 1.0
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: 1
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: f3e1957e-ea20-4058-8e10-b7e303fde16a
10-25 15:22:13.788 3871-3911/com.tpb.hn W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
10-25 15:22:13.788 3871-3911/com.tpb.hn A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3911 (RenderThread)
[ 10-25 15:22:13.788 1181: 1181 W/ ]
debuggerd: handling request: pid=3871 uid=10066 gid=10066 tid=3911
loadUrl is when the WebView starts loading
I have read posts about Fatal signal 6 code -6, but none have offered a solution.
Any help is much appreciated.
Edit- I removed the default invisibility of the WebView, and the code changing it, and got a much larger trace with more detail.
I can't post it here as the post ends up at 59000 characters, but it is now on PasteBin Here
回答1:
I had a similar issue. In my case, the problem was with this code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
I removed this line of code, and my app stoped crashing. I faced with this issue on Android N.
BTW Hardware acceleration is enabled by default if your Target API level is >=14
and i think this line of code is redundant.
回答2:
Well, I found a way to get the behaviour I want. But not to fix the original problem.
I found this StackOverflow post which suggested extending WebView and implementing NestedScrollingChild as has been done here (Apache2).
This works perfectly. However, it is not a solution to the actual problem.
The layout now reads
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/browser_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/browser_loading_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="@color/colorAccent"
android:layout_gravity="center"/>
<com.tpb.hn.story.NestedWebView
android:id="@+id/browser_webview"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
</com.tpb.hn.story.NestedWebView>
</LinearLayout>
The only change being adding the layout_behavior.
回答3:
i has same issue and then i added code delayed handler
private void loadJavaScript(String script) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (mWebView != null) {
mWebView.evaluateJavascript(script, null);
return;
}
}
loadPage("javascript:" + script);
}
}, 500); //this
}
来源:https://stackoverflow.com/questions/40242623/webview-in-nestedscrollview-gives-fatal-signal-6-sigabrt-code-6-renderthread