You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启用react-native-screens时,渲染含iframe的<HTML/>组件返回首页致Android崩溃

React Native应用返回首页崩溃问题(react-native-screens + 含iframe的
return (<HTML/>)
组件场景)

结合你的场景和崩溃日志,我来梳理下问题细节和可行的解决方向:

首先明确触发崩溃的场景:当启用react-native-screens库后,在渲染带有iframe元素的<HTML/>组件页面中,点击返回按钮回到首页时应用直接崩溃。

环境信息

  • React Native: 0.61.5
  • react-native-render-html: 4.2.2
  • react-native-webview: 10.3.2
  • react-native-screens: 2.8.0
  • react-native-render-html-table-bridge: 0.6.1

崩溃日志

07-29 17:41:49.173 6901 6901 F crashpad: dlopen: dlopen failed: library "libandroidicu.so" not found: needed by /system/lib/libharfbuzz_ng.so in namespace (default)
--------- beginning of crash
07-29 17:41:49.176 6410 6441 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c in tid 6441 (RenderThread), pid 6410 (com.newmednav)
07-29 17:41:49.340 6904 6904 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-29 17:41:49.340 6904 6904 F DEBUG : Build fingerprint: 'google/sdk_gphone_x86_arm/generic_x86_arm:11/RPB2.200611.009/6625208:userdebug/dev-keys'
07-29 17:41:49.340 6904 6904 F DEBUG : Revision: '0'
07-29 17:41:49.340 6904 6904 F DEBUG : ABI: 'x86'
07-29 17:41:49.340 6904 6904 F DEBUG : Timestamp: 2020-07-29 17:41:49+0545
07-29 17:41:49.340 6904 6904 F DEBUG : pid: 6410, tid: 6441, name: RenderThread >>> com.newmednav <<<
07-29 17:41:49.340 6904 6904 F DEBUG : uid: 10152
07-29 17:41:49.340 6904 6904 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c
07-29 17:41:49.340 6904 6904 F DEBUG : Cause: null pointer dereference
07-29 17:41:49.340 6904 6904 F DEBUG : eax efbc2cb0 ebx eed5c69c ecx eed52a80 edx 00000000
07-29 17:41:49.341 6904 6904 F DEBUG : edi d139ae90 esi 00000000
07-29 17:41:49.341 6904 6904 F DEBUG : ebp c086ed48 esp c086eb50 eip ee698c1c
07-29 17:41:49.425 6904 6904 F DEBUG : backtrace:
07-29 17:41:49.425 6904 6904 F DEBUG : #00 pc 00247c1c /system/lib/libhwui.so (android::uirenderer::skiapipeline::GLFunctorDrawable::onDraw(SkCanvas*)+1548) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425 6904 6904 F DEBUG : #01 pc 00303a57 /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+87) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425 6904 6904 F DEBUG : #02 pc 002f4606 /system/lib/libhwui.so (SkBaseDevice::drawDrawable(SkDrawable*, SkMatrix const*, SkCanvas*)+38) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425 6904 6904 F DEBUG : #03 pc 00659291 /system/lib/libhwui.so (SkGpuDevice::drawDrawable(SkDrawable*, SkMatrix const*, SkCanvas*)+353) (BuildId: 434a9b68672e1dd2b15599730362463d)
07-29 17:41:49.425 6904 6904 F DEBUG : #04 pc 002d9dc0 /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+48) (BuildId: 434a9b68672e1dd2b15599730362463d)

可行的解决思路

从日志里的SIGSEGV(空指针解引用)和调用栈来看,问题出在UI渲染线程,结合你的使用场景,大概率是react-native-screens的页面销毁机制和react-native-webview(

return (<HTML/>)
组件依赖它渲染iframe)的资源释放逻辑冲突导致的。你可以按以下顺序尝试解决:

1. 临时禁用当前页面的screens优化

这是最快的验证方法,在包含

return (<HTML/>)
组件的页面中,关闭react-native-screens的支持,避免它的生命周期管理和webview冲突:

import { enableScreens } from 'react-native-screens';
import { useEffect } from 'react';

function HtmlWithIframePage() {
  useEffect(() => {
    // 进入页面时关闭screens
    enableScreens(false);
    // 离开页面时恢复全局设置
    return () => enableScreens(true);
  }, []);

  // 你的页面渲染逻辑...
  return <HTML html={yourHtmlWithIframe} />;
}

2. 提前清理iframe资源

在页面即将返回前,手动清理

return (<HTML/>)
组件的内容,确保webview的iframe资源提前释放:

function HtmlWithIframePage({ navigation }) {
  const [htmlContent, setHtmlContent] = useState(yourHtmlWithIframe);

  useEffect(() => {
    const unsubscribe = navigation.addListener('beforeRemove', () => {
      // 清空HTML内容,触发webview资源清理
      setHtmlContent('');
    });

    return unsubscribe;
  }, [navigation]);

  return <HTML html={htmlContent} />;
}

3. 升级依赖版本

你使用的依赖版本都比较老旧(比如RN 0.61.5是2020年的版本),这些库后续版本大概率修复了这类兼容性问题。优先尝试:

  • 升级react-native-screens到适配RN 0.61.x的最新稳定版
  • 升级react-native-render-html和react-native-webview到对应兼容版本
    注意升级时要仔细看各库的升级文档,避免版本不兼容导致新问题。

4. 修复Android系统库依赖问题

日志开头提到libandroidicu.so找不到,虽然这可能是测试设备的系统问题,但可以尝试在android/app/build.gradle中添加配置确保ICU库被正确打包:

android {
  // ...其他配置
  packagingOptions {
    pickFirst 'lib/x86/libicuuc.so'
    pickFirst 'lib/x86_64/libicuuc.so'
    pickFirst 'lib/armeabi-v7a/libicuuc.so'
    pickFirst 'lib/arm64-v8a/libicuuc.so'
  }
}

内容的提问来源于stack exchange,提问作者Deepak Bhattarai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 17:47:28