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

Xcode 15.4执行flutter run遇Command CodeSign非零退出码错误求助

Xcode 15.4 Flutter模拟器代码签名错误解决方案

问题背景

  • Xcode版本:15.4
  • 运行环境:iPhone 15 Pro模拟器
  • 执行命令:flutter run
  • Pod版本:1.15.2
  • 已在Podfile中添加以下post_install脚本:
post_install do |installer|
  installer.pods_project.targets.each do |target|
     flutter_additional_ios_build_settings(target)
      target.build_configurations.each do |config|
        xcconfig_path = config.base_configuration_reference.real_path
        xcconfig = File.read(xcconfig_path)
        xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
        File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
      end
  end
end
  • 仍出现错误:
Uncategorized (Xcode): Command CodeSign failed with a nonzero exit code

解决步骤

1. 检查模拟器签名配置

打开iOS项目的ios/Runner.xcworkspace,选中Runner target → Build Settings → 搜索Code Signing Identity,确保Debug配置下选择iOS Simulator Signing Identity或Automatic,避免选择真机证书。

2. 清理缓存并重新构建

依次执行以下命令:

flutter clean
cd ios
pod deintegrate
pod cache clean --all
pod install
cd ..
flutter run

3. 更新CocoaPods版本

当前1.15.2版本与Xcode 15.4存在兼容性问题,更新到最新稳定版:

sudo gem install cocoapods

更新完成后重新执行cd ios && pod install。

4. 修改Podfile脚本,强制关闭模拟器签名要求

在现有post_install脚本中添加签名相关配置,修改后脚本如下:

post_install do |installer|
  installer.pods_project.targets.each do |target|
     flutter_additional_ios_build_settings(target)
     target.build_configurations.each do |config|
       # 新增:禁用模拟器签名要求
       config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
       config.build_settings['CODE_SIGNING_REQUIRED'] = 'NO'
       config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
       # 原有替换逻辑
       xcconfig_path = config.base_configuration_reference.real_path
       xcconfig = File.read(xcconfig_path)
       xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
       File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
     end
  end
end

保存后执行cd ios && pod install。

5. 确认Xcode命令行工具版本

打开Xcode → 设置(Settings)→ Locations,确保Command Line Tools选择的是Xcode 15.4,不要选择旧版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 21:13:32