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

Xcode 13.2.1打包Archive遇Command PhaseScriptExecution非零退出码错误

Flutter iOS归档构建失败排查记录

问题概述

使用Xcode 13.2.1(因Mac设备老旧无法升级至最新版本)构建Flutter项目归档时失败,但在模拟器上可正常完成构建。已尝试排查同类问题并进行相关修改,问题仍未解决。

错误日志

PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/selsa/Library/Developer/Xcode/DerivedData/Runner-gvvqzxpfetwxdobvettmuxwhyjau/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Script-CD8053175E8846FE90FD427D.sh (in target 'Runner' from project 'Runner')

mkdir -p /Users/selsa/Library/Developer/Xcode/DerivedData/Runner-gvvqzxpfetwxdobvettmuxwhyjau/Build/Intermediates.noindex/ArchiveIntermediates/Runner/BuildProductsPath/Release-iphoneos/Runner.app/Frameworks
Symlinked...
readlink: illegal option -- f
usage: readlink [-n] [file ...]
Command PhaseScriptExecution failed with a nonzero exit code

当前Podfile配置

platform :ios, '12.0'

# 禁用CocoaPods统计以降低Flutter构建延迟
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} 必须存在。如果手动执行pod install,请确保先运行flutter pub get"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "在#{generated_xcode_build_settings_path}中未找到FLUTTER_ROOT。尝试删除Generated.xcconfig后重新运行flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
  installer.generated_projects.each do |project|
    project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
         end
    end
  end
end

已执行的修改操作

  • 调整了Runner的Xcode配置(已按截图完成设置)
  • 修改frameworks.sh文件,添加以下代码片段:
if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi
  • 更新Podfile的post_install钩子:
    修改前代码:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
      end
    end
    
    修改后代码:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
      end
      installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
             end
        end
      end
    end
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 18:15:10