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

Flutter集成Firebase Crashlytics后Xcode编译报错:参数列表过长

解决Xcode编译时"unable to spawn process '/bin/sh' (Argument list too long)"报错

问题背景

Flutter 3.13.4项目集成Firebase Crashlytics后,使用Visual Studio Code运行应用一切正常,但通过Xcode编译时触发以下错误:

PhaseScriptExecution [CP]\ Check\ Pods\ Manifest.lock /Users/meghapradeetha/Library/Developer/Xcode/DerivedData/Runner-eujtueznukosgeaurmvdxxxxvzqf/Build/Intermediates.noindex/Runner.build/Debug-uat-iphonesimulator/Runner.build/Script-CF008D9BDBCCC338375EC5F7.sh (in target 'Runner' from project 'Runner')
    cd /Users/meghapradeetha/GitHub/MobileApp/ios
    /bin/sh -c /Users/meghapradeetha/Library/Developer/Xcode/DerivedData/Runner-eujtueznukosgeaurmvdxxxxvzqf/Build/Intermediates.noindex/Runner.build/Debug-uat-iphonesimulator/Runner.build/Script-CF008D9BDBCCC338375EC5F7.sh

error: unable to spawn process '/bin/sh' (Argument list too long) (in target 'Runner' from project 'Runner')

已尝试常见相关解决方案,但问题未解决。

项目相关配置

Debug.xcconfig

#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-dev.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-qa.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-uat.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-prod.xcconfig"
#include "Generated.xcconfig"

Release.xcconfig

#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-dev.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-qa.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-uat.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-prod.xcconfig"
#include "Generated.xcconfig"

Podfile

# Uncomment this line to define a global platform for your project
# platform :ios, '14.0'

# Disable CocoaPods analytics to improve build latency
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

# Define the project and configurations
project 'Runner', {
  'Debug' => :debug,
  'Debug-dev' => :debug,
  'Debug-qa' => :debug,
  'Debug-uat' => :debug,
  'Debug-prod' => :release,
  'Profile' => :release,
  'Profile-dev' => :release,
  'Profile-qa' => :debug,
  'Profile-uat' => :debug,
  'Profile-prod' => :release,
  'Release' => :release,
  'Release-dev' => :release,
  'Release-qa' => :release,
  'Release-uat' => :release,
  'Release-prod' => :release,
}

# Define the path to Flutter
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} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

# Include Flutter pod helper
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

# Set up the target for 'Runner'
target 'Runner' do
  use_frameworks!
  
  # Add the Firebase Crashlytics pod
  pod 'Firebase/Crashlytics'
  
  # Install Flutter pods
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

# Post-installation configurations
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # Define preprocessor definitions for Dart Permissions
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        # Dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',
        'PERMISSION_LOCATION=1',
      ]
      
      # Apply additional Flutter build settings
      flutter_additional_ios_build_settings(target)
    end
  end
end

Pubspec.yaml

内容见对应截图

解决方案

核心原因

Debug.xcconfig和Release.xcconfig中同时导入了所有环境的Pods配置文件,每个Pods配置会重复定义大量环境变量,叠加后超出系统允许的命令行参数长度限制,导致Xcode无法启动shell进程执行构建脚本。

修复步骤

  1. 简化xcconfig文件导入

    • 修改Debug.xcconfig,只保留基础Debug配置和Generated配置:
      #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
      #include "Generated.xcconfig"
      
    • 修改Release.xcconfig,只保留基础Release配置和Generated配置:
      #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
      #include "Generated.xcconfig"
      
    • 打开Xcode,进入Runner target的Build Settings页面,为每个自定义配置(如Debug-uat)设置对应的Pods配置:找到Based On选项,选择匹配的Pods-Runner.debug-uat(或对应环境配置)。
  2. 清理缓存并重建依赖

    • 删除ios目录下的Pods文件夹和Podfile.lock文件
    • 执行命令:flutter clean
    • 进入ios目录,执行:pod install
    • 重启Xcode,执行Clean Build Folder(快捷键Cmd+Shift+K)
  3. 验证Podfile配置
    确保Podfile中自定义配置与CocoaPods的debug/release映射正确,避免生成冗余配置项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 14:55:04