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

React Native 0.70.1在M1 Monterey执行run-ios报错,Xcode14构建正常求助

React Native 0.70.1 + Xcode 14 M1环境下run-ios YogaKit构建错误解决办法

问题复现

在React Native 0.70.1、Xcode 14、Monterey M1环境下,执行npx react-native run-ios时出现以下错误:

The following build commands failed:
    SwiftEmitModule normal arm64 Emitting\ module\ for\ YogaKit (in target 'YogaKit' from project 'Pods')

但直接在Xcode 14中构建项目可成功完成。此前尝试在DEBUG Build Setting中排除arm64、在Podfile中统一设置最低iOS版本均无效。

解决步骤

1. 彻底清理依赖与缓存

执行以下命令清理项目缓存并重新安装依赖:

# 清理Node依赖
rm -rf node_modules
npm cache clean --force
npm install

# 清理iOS端Pods
cd ios
rm -rf Pods Podfile.lock
pod deintegrate
pod install --repo-update
cd ..

2. 针对YogaKit单独配置编译参数

修改项目根目录下的Podfile,在post_install块中添加YogaKit的专属配置,解决Swift版本与架构兼容问题:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    # 统一设置最低iOS版本为12.0
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
    end

    # 单独处理YogaKit目标
    if target.name == 'YogaKit'
      target.build_configurations.each do |config|
        # 指定Swift版本为5.0,适配Xcode 14编译规则
        config.build_settings['SWIFT_VERSION'] = '5.0'
        # 针对模拟器和真机分别排除不兼容架构
        config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
        config.build_settings['EXCLUDED_ARCHS[sdk=iphoneos*]'] = 'i386'
      end
    end
  end
end

修改完成后回到ios目录执行pod install。

3. 指定架构执行run-ios命令

执行run-ios时显式指定x86_64架构,规避M1模拟器的架构冲突:

npx react-native run-ios --simulator="iPhone 14" --arch=x86_64

也可以在package.json的scripts中添加快捷命令:

"scripts": {
  "ios": "react-native run-ios --arch=x86_64"
}

之后直接运行npm run ios即可。

4. 确认Xcode命令行工具版本一致性

打开Xcode → 偏好设置 → 位置 → 命令行工具,选择当前安装的Xcode 14版本,确保命令行工具与GUI版本一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 18:16:07