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

React Native PDF报getConstants读取null错误,求适配Android11的兼容版本

适配React Native 0.72.6(安卓11)的依赖版本方案

问题定位

can not read getConstants null错误本质是原生模块初始化失败,无法读取常量,核心原因是依赖版本与React Native 0.72.6不兼容,或模块链接未完成。

验证通过的版本组合

  • React Native: 0.72.6(保留当前版本)
  • react-native-pdf: 6.6.2
  • react-native-blob-util: 0.17.0

操作步骤

  1. 卸载现有冲突依赖:
    npm uninstall react-native-pdf react-native-blob-util
    # 若使用yarn:
    yarn remove react-native-pdf react-native-blob-util
    
  2. 安装指定适配版本:
    npm install react-native-pdf@6.6.2 react-native-blob-util@0.17.0
    # 若使用yarn:
    yarn add react-native-pdf@6.6.2 react-native-blob-util@0.17.0
    
  3. 清理缓存并重建项目:
    npm cache clean --force
    npx react-native start --reset-cache
    cd android && ./gradlew clean && cd .. && npx react-native run-android
    

额外注意事项

  • 检查安卓项目android/build.gradle中minSdkVersion是否设置为23及以上(安卓11对应SDK 30,minSdk23可兼容)。
  • 由于react-native-pdf依赖原生配置,建议使用Expo裸工作流,避免预构建模式的自动链接冲突。

内容的提问来源于stack exchange,提问作者Jhonson Ayalew

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 11:42:01