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

Mac Ventura 13.4下React Native iOS构建失败求助

React Native iOS构建失败:React-Codegen编译错误

问题详情

React Native 0.71.4应用在Android和MacOS 11上构建正常,但在MacOS 13.4 + Xcode 14.3环境下构建iOS版本时,出现React-Codegen编译失败错误:

** BUILD FAILED **

The following build commands failed:
    CompileC /Users/user/Library/Developer/Xcode/DerivedData/SynkBooks-bghxbttcyzckrieohotoymzblpqz/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Codegen.build/Objects-normal/x86_64/FBReactNativeSpec-generated.o /Users/user/Desktop/Work/synkbooks_app_v1/ios/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-Codegen' from project 'Pods')
(1 failure)

已尝试升级Ruby版本至3.2.0,环境信息如下:

System:
    OS: macOS 13.4
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
    Memory: 310.96 MB / 31.63 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    Watchman: 2023.05.22.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/user/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.10121639
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.4 => 0.71.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

解决建议

  • 清理缓存与构建产物

    1. 清理React Native缓存:
      npx react-native clean
      
    2. 进入iOS目录,清理Pod缓存和构建文件:
      cd ios
      rm -rf Pods Podfile.lock build
      pod deintegrate
      pod cache clean --all
      
  • 重新安装依赖与Pods

    1. 回到项目根目录,重新安装npm依赖:
      npm install
      # 或使用yarn
      yarn install
      
    2. 进入iOS目录,重新安装Pods:
      cd ios
      pod install --repo-update
      
  • 调整Xcode编译设置

    1. 打开Xcode项目,找到Pods项目下的React-Codegen目标
    2. 进入Build Settings,搜索Apple Clang - Language - C++
    3. 将C++ Standard Library设置为libc++ (LLVM C++ standard library with C++11 support)
    4. 同时检查Build Options下的Enable Modules (C and Objective-C)是否设为Yes
  • 更新CocoaPods版本
    当前使用的CocoaPods 1.12.1可能与Xcode 14.3存在兼容性问题,尝试升级到最新稳定版:

    gem install cocoapods
    
  • 检查架构兼容性

    1. 在Xcode中,项目目标的Build Settings里搜索Architectures
    2. 确保Architectures设置为Standard Architectures (arm64, x86_64)
    3. 关闭Build Active Architecture Only(Debug模式下可暂时开启,但Release模式需关闭)
  • 重新生成Codegen文件
    手动触发Codegen生成:

    npx react-native generate-codegen-artifacts --path ./package.json --output-path ./ios/build/generated
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 14:05:35