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

React Native开启iOS Hermes遇RCT-Folly的fmt/compile.h找不到错误

解决方案

问题原因

RN 0.66.x版本内置的RCT-Folly依赖配置在use_frameworks!动态链接模式下存在缺陷,fmt作为RCT-Folly的依赖库,其头文件路径没有被正确加入RCT-Folly的编译搜索路径,导致编译时找不到fmt/compile.h文件。

解决步骤

  • 第一步:修改Podfile,在末尾添加post_install钩子修正RCT-Folly的头文件搜索路径,完整配置参考如下:
platform :ios, '12.0'
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
use_frameworks!

workspace 'MyWorkspace'

# Default spec repo
source 'https://github.com/CocoaPods/Specs.git'

...

target 'MyTarget' do
    project 'MyProject'

    config = use_native_modules!

    use_react_native!(
        :path => config[:reactNativePath],
        # to enable hermes on iOS, change `false` to `true` and then install pods
        :hermes_enabled => true
    )
    
    ...

end

# 新增以下配置修正头文件搜索路径
post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RCT-Folly'
      target.build_configurations.each do |config|
        config.build_settings['HEADER_SEARCH_PATHS'] ||= []
        # 追加fmt库的头文件搜索路径
        config.build_settings['HEADER_SEARCH_PATHS'] << '$(PODS_ROOT)/fmt/include'
        config.build_settings['ALWAYS_SEARCH_USER_PATHS'] = 'YES'
      end
    end
  end
end

如果你的Podfile中已经存在post_install钩子,只需要将里面针对RCT-Folly的配置逻辑合并到原有钩子中即可,不要重复声明post_install。

  • 第二步:清理原有Pod缓存重新安装依赖:
# 进入项目ios目录
cd ios
# 删除旧的Pod配置文件
rm -rf Pods Podfile.lock
pod deintegrate
# 重新安装Pod依赖
pod install --repo-update

完成后重新编译项目即可正常运行,不需要修改use_frameworks!动态链接配置,也不影响Hermes引擎的正常使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 12:27:10