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

React Native最新版本出现[RNScreens] onHostResume虚拟布局初始化失败问题

解决React Native 0.76.0中[RNScreens] Failed to initialise dummy layout in onHostResume错误

问题背景

在使用React Native 0.76.0时,出现错误提示:[RNScreens] Failed to initialise dummy layout in onHostResume,项目依赖配置如下:

"dependencies": {
    "@react-native-async-storage/async-storage": "^2.0.0",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "@reduxjs/toolkit": "^2.3.0",
    "patch-package": "^8.0.0",
    "postinstall-postinstall": "^2.1.0",
    "react": "18.3.1",
    "react-native": "0.76.0",
    "react-native-contacts": "^8.0.3",
    "react-native-safe-area-context": "^4.11.1",
    "react-native-screens": "^3.34.1",
    "react-redux": "^9.1.2",
    "redux-persist": "^6.0.0"
}

错误截图:
错误截图

解决方案

1. 更新react-native-screens到兼容版本

react-native-screens 3.x版本与RN 0.76.0存在兼容性问题,需升级到4.x系列:

  • 卸载当前版本:
    npm uninstall react-native-screens
    
  • 安装适配版本:
    npm install react-native-screens@^4.0.0
    

2. 清理缓存并重新构建

  • 清除npm缓存:
    npm cache clean --force
    
  • 重置Metro缓存:
    npx react-native start --reset-cache
    
  • 重新安装依赖:
    npm install
    
  • 针对Android项目清理gradle缓存:
    cd android && ./gradlew clean && cd ..
    
  • 重新运行项目:
    npx react-native run-android
    

3. 检查Android MainActivity配置

确保MainActivity继承自ReactActivity,若自定义onHostResume方法,必须调用super.onHostResume(),避免覆盖原生逻辑导致冲突。

4. 降级React Native版本(备选)

若上述方案无效,可暂时降级RN到0.75.x版本(与screens 3.x兼容性更稳定):

  • 安装RN 0.75.4:
    npm install react-native@0.75.4
    
  • 匹配对应的React版本:
    npm install react@18.2.0
    

内容的提问来源于stack exchange,提问作者Engr.Aftab Ufaq

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 20:40:01