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

使用xcodebuild归档含RxSwift依赖的Framework时RxCocoa失败

解决SPM引入RxSwift时xcodebuild归档失败的问题

问题场景

通过SPM引入RxSwift 6.6.0的iOS Framework,执行以下xcodebuild归档脚本失败:

xcodebuild archive \
    -project Project.xcodeproj \
    -scheme Scheme \
    -destination "generic/platform=iOS" \
    -archivePath "archives/Release-iOS" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES \

报错信息:

** ARCHIVE FAILED **

The following build commands failed:
    SwiftVerifyEmittedModuleInterface normal arm64 Verifying\ emitted\ module\ interface\ RxCocoa.private.swiftinterface /Users/.../DerivedData/Project-ericldteywlbdydxfxsgvkaxpvdj/Build/Intermediates.noindex/ArchiveIntermediates/Project/IntermediateBuildFilesPath/RxSwift.build/Release-iphoneos/RxCocoa.build/Objects-normal/arm64/RxCocoa.private.swiftinterface (in target 'RxCocoa' from project 'RxSwift')
    SwiftVerifyEmittedModuleInterface normal arm64 Verifying\ emitted\ module\ interface\ RxCocoa.swiftinterface /Users/.../DerivedData/Project-ericldteywlbdydxfxsgvkaxpvdj/Build/Intermediates.noindex/ArchiveIntermediates/Project/IntermediateBuildFilesPath/RxSwift.build/Release-iphoneos/RxCocoa.build/Objects-normal/arm64/RxCocoa.swiftinterface (in target 'RxCocoa' from project 'RxSwift')
(2 failures)

手动通过Xcode(Product->Archive)归档可成功,当前使用Xcode 14.3.1版本。

可行解决方案

  • 方案1:添加EXCLUDED_ARCHS参数临时规避
    在xcodebuild命令中加入架构排除参数,适合快速测试场景:

    xcodebuild archive \
        -project Project.xcodeproj \
        -scheme Scheme \
        -destination "generic/platform=iOS" \
        -archivePath "archives/Release-iOS" \
        SKIP_INSTALL=NO \
        BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
        EXCLUDED_ARCHS=arm64
    
  • 方案2:修改RxCocoa目标的分发编译设置
    找到SPM引入的RxSwift项目中,RxCocoa目标的Build Library for Distribution选项,将其设置为NO。Xcode手动归档时可能自动忽略了依赖库的该设置,而命令行模式会严格执行。

  • 方案3:清理DerivedData后重新执行
    先删除对应项目的DerivedData目录,再重新执行归档命令:

    rm -rf ~/Library/Developer/Xcode/DerivedData/Project-ericldteywlbdydxfxsgvkaxpvdj
    xcodebuild archive \
        -project Project.xcodeproj \
        -scheme Scheme \
        -destination "generic/platform=iOS" \
        -archivePath "archives/Release-iOS" \
        SKIP_INSTALL=NO \
        BUILD_LIBRARY_FOR_DISTRIBUTION=YES
    
  • 方案4:改用workspace执行归档(若有对应文件)
    如果项目存在.xcworkspace文件,替换-project参数为-workspace,SPM依赖在workspace环境下的处理更稳定:

    xcodebuild archive \
        -workspace Project.xcworkspace \
        -scheme Scheme \
        -destination "generic/platform=iOS" \
        -archivePath "archives/Release-iOS" \
        SKIP_INSTALL=NO \
        BUILD_LIBRARY_FOR_DISTRIBUTION=YES
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 05:40:03