ScrollView嵌套WebView报Unable to create layer for WebView

本文探讨了在强制GPU渲染模式下,WebView加载H5页面时出现崩溃的问题。通过分析崩溃日志,发现GPU渲染存在大小限制,导致崩溃。尝试使用软件层类型设置和transitionGroup属性未解决问题。文章记录了问题现状,寻求进一步研究。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今早一上班就有客户的奔溃bug,具体复现步骤,开发者选项-强制gpu渲染,点开会奔溃的页面页面布局如下图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
                <com.example.base.jsbridge2.WVJBWebView
                    android:layerType="software"
                    android:id="@+id/web_view_topman"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                </com.example.base.jsbridge2.WVJBWebView>
        </ScrollView>
</LinearLayout>

先说下为什么嵌套scrollView,因为加载的h5页面滑动回回弹,实在没办法才加的scrollView;

然后就出现奔溃了,奔溃日志如下

java.lang.IllegalStateException: Unable to create layer for WVJBWebView
	at android.os.MessageQueue.nativePollOnce(Native Method)
	at android.os.MessageQueue.next(MessageQueue.java:143)
	at android.os.Looper.loop(Looper.java:130)
	at android.app.ActivityThread.main(ActivityThread.java:6141)
	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:1399)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

百度了一大堆都说 解决方法: 
webView.setLayerType(View.LAYER_TYPE_NONE, null); 
关闭硬件加速即可,也不能使用软件加速

但是用户他就是强制gpu渲染,我能怎么办,把他手机拿来关了吗。。。。

然后本着再研究研究的态度,然后我就继续看,

看到https://bugs.chromium.org/p/chromium/issues/detail?id=578150这个网友问题跟我一样,然后说是gpu渲染的大小是有限的,所以导致的奔溃,然后我就开始研究怎么解决渲染的问题,然后我发现这个代码有人说道

android:transitionGroup="true"

 用法如下链接 https://blog.youkuaiyun.com/zhaostrong/article/details/79043142

但是我用了 还是没解决我的问题,暂时先到这吧,先记录下,找机会再研究下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值