M1 Pro Mac下iOS项目编译失败问题求助
解决M1 Pro Mac + CocoaPods + GoogleAnalytics编译问题
一、修复架构不匹配问题(替代全局添加Excluded Architectures)
直接给所有Target加arm64到排除架构容易触发脚本冲突,换精准配置:
- 打开项目Project级Build Settings(不是单个Target的)
- 找到
Excluded Architectures,针对Debug模式的Any iOS Simulator SDK添加arm64 - 保持
Build Active Architecture Only的Debug设为Yes,Release设为No - 修改Podfile,添加以下代码让CocoaPods自动适配Pods Target的架构:
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| if config.name == 'Debug' && config.sdk_name&.include?('simulator') config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' end end end end
- 终端执行
pod install重新安装依赖
二、解决Command PhaseScriptExecution失败问题
如果架构配置后仍报错,按以下步骤排查:
- 查看Xcode Report Navigator里的错误详情,定位具体是哪个脚本出错(比如Pods的frameworks脚本或自定义脚本)
- 若报错脚本是CocoaPods生成的,检查Podfile里的自定义post_install脚本是否有冲突,或某个第三方Pod的安装脚本存在路径问题
- 给报错脚本添加执行权限:终端中执行
chmod +x 脚本完整路径(比如chmod +x Pods/Target Support Files/Pods-YourProject/Pods-YourProject-frameworks.sh) - 关闭Xcode的Rosetta模式:右键Xcode图标→显示简介→取消勾选“使用Rosetta打开”,M1 Pro原生编译更稳定,Rosetta可能导致路径混乱
- 彻底清理缓存:终端执行
pod deintegrate && pod clean,删除Derived Data后重新pod install
内容的提问来源于stack exchange,提问作者Dev11_1
相关产品推荐
相关产品推荐

