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

Xcode 14下React Native 0.65构建失败:typedef重定义错误求助

解决React Native 0.65 + Xcode 14构建时RCT-Folly的typedef重定义错误

以下是针对该问题的具体解决步骤:

方法1:修改Podfile配置(最常用)

打开项目根目录下的ios/Podfile,在文件末尾的post_install块中添加针对RCT-Folly的编译配置:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "RCT-Folly"
      target.build_configurations.each do |config|
        # 添加编译宏解决typedef重定义问题
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
          '$(inherited)',
          'FOLLY_NO_CONFIG=1',
          'FOLLY_MOBILE=1',
          'FOLLY_USE_LIBCPP=1'
        ]
        # 关闭64位转32位的编译警告
        config.compiler_flags = '-Wno-shorten-64-to-32'
      end
    end
  end
end

修改完成后执行以下命令重新安装依赖:

cd ios
pod deintegrate
pod install
cd ..

方法2:锁定RCT-Folly版本并启用模块化头文件

若方法1无效,尝试在Podfile中明确指定RCT-Folly的podspec路径并启用模块化头文件:

# 替换原有RCT-Folly的引用(若存在)
pod 'RCT-Folly', :podspec => '../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec', :modular_headers => true

完成后同样执行pod deintegrate和pod install重新安装依赖。

方法3:手动调整Xcode编译设置

如果Podfile修改不生效,可直接在Xcode中操作:

  1. 打开ios目录下的.xcworkspace文件
  2. 在左侧导航栏找到Pods -> Targets -> RCT-Folly
  3. 切换到Build Settings标签页
    • 搜索Preprocessor Macros,添加宏:FOLLY_NO_CONFIG=1、FOLLY_MOBILE=1、FOLLY_USE_LIBCPP=1
    • 搜索Other C Flags,添加-Wno-shorten-64-to-32
  4. 按Command + Shift + K清理Xcode缓存后重新构建

方法4:彻底清理项目缓存

若以上方法均无效,执行以下命令彻底清理所有缓存后重试:

# 清理Node依赖
rm -rf node_modules
rm yarn.lock
yarn install

# 清理iOS Pod依赖
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..

# 清理React Native缓存
watchman watch-del-all
rm -rf $TMPDIR/react-native-packager-cache-*
rm -rf $TMPDIR/metro-*

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 18:31:03