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

Xcode 13使用SPM构建时出现Argument list too long错误如何解决?

Xcode 13 SPM 构建「Argument list too long」报错修复方案

问题现象

在项目中使用SPM(Swift Package Manager)管理依赖,通过Xcode 13构建项目时出现Argument list too long报错,排查后发现构建参数中存在大量重复的-F /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/PackageFrameworks标识,完整构建日志片段如下:

CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'TryToReproduce' from project 'MyProject')
    cd /Users/renat/Sources/MyProject
    export DEVELOPER_DIR\=/Applications/Xcode-13.0.0.app/Contents/Developer
    export SDKROOT\=/Applications/Xcode-13.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk
    /Applications/Xcode-13.0.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc

...
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxCocoa
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxRelay
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxSwift
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/TensorFlowLiteSwift
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxCocoa
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxRelay
-I /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/RxSwift
-F /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/PackageFrameworks
-F /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator/PackageFrameworks
// 大量重复-F参数省略
-F /Users/renat/DerivedData/Build/Products/Debug-iphonesimulator
-F /Users/renat/Sources/release-ios/ios/Pods/TensorFlowLiteC/Frameworks
-F /Users/renat/Sources/release-ios/ios/Pods/YandexMapKit
-F /Users/renat/Sources/release-ios/ios/Pods/YandexRuntime
-F /Users/renat/Sources/release-ios/ios/lib
-F /Users/renat/Sources/release-ios/iOS
...

修复方案

  • 优先升级Xcode版本
    该问题属于Xcode 13的官方已知SPM缺陷,苹果在Xcode 13.4.1及之后的版本中修复了SPM重复添加Framework搜索路径的逻辑,升级到对应版本后即可直接解决问题。
  • 必须保留Xcode 13版本的临时修复方案
    • 调整依赖链接类型:在Package.swift中显式将所有可调整的SPM依赖的库类型指定为静态库,避免动态库多次引用导致路径重复添加:
      .library(name: "xxx", type: .static, targets: ["xxx"])
      
    • 缩短构建路径:打开Xcode偏好设置 -> Locations,将DerivedData的存储路径修改为根目录下的短路径(例如/build/dd),减少每条-F参数的字符长度,暂时规避参数列表超长的问题。
    • 添加自定义编译脚本去重:在项目的Build Phases中新增一个Run Script,放在Compile Sources之前,执行参数去重逻辑,过滤重复的Framework搜索路径。
    • 混合使用CocoaPods的场景下,将Podfile中的use_frameworks!修改为use_frameworks! :linkage => :static,减少动态库数量,降低路径重复概率。

内容的提问来源于stack exchange,提问作者G.Renat

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 10:36:03