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

企业代理环境下xcodebuild拉取SwiftPM二进制依赖失败求助

企业内网环境下xcodebuild无法下载SwiftPM二进制依赖的问题

构建命令

执行的xcodebuild命令如下:

XCODE_OPTIONS="-scmProvider system -resolvePackageDependencies -disablePackageRepositoryCache"

xcodebuild clean $XCODE_OPTIONS -workspace $WORKSPACE -scheme $SCHEME

错误信息

构建时出现无法下载二进制xcframework的错误:

Command line invocation:
    /Applications/Xcode_16.2.app/Contents/Developer/usr/bin/xcodebuild -scmProvider system -resolvePackageDependencies -disablePackageRepositoryCache clean -workspace SomeApp.xcworkspace -scheme SomeAppTest
User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES
Resolve Package Graph
failed downloading 'https://github.com/getsentry/sentry-cocoa/releases/download/8.52.1/Sentry.xcframework.zip' which is required by binary target 'Sentry': downloadError("Could not connect to the server.")failed downloading 'https://storage.mds.yandex.net/get-appmetrica-mobile-sdk/175948/YandexMobileMetrica-4.5.2-ios-spm-4cf9781b-4e3e-4674-bbb3-5ab28cc9869a.zip' which is required by binary target 'YandexMobileMetrica': downloadError("Could not connect to the server.")failed downloading 'https://github.com/getsentry/sentry-cocoa/releases/download/8.52.1/Sentry-Dynamic.xcframework.zip' which is required by binary target 'Sentry-Dynamic': downloadError("Could not connect to the server.")failed downloading 'https://storage.mds.yandex.net/get-appmetrica-mobile-sdk/50347/YandexMobileMetricaCrashes-4.5.2-ios-spm-3ac18632-911c-404d-8f4d-4d2a496ee5b7.zip' which is required by binary target 'YandexMobileMetricaCrashes': downloadError("Could not connect to the server.")fatalError
2025-06-10 13:59:51.959 xcodebuild[96745:70697693] Writing error result bundle to /tmp/ResultBundle_2025-10-06_13-59-0051.xcresult
xcodebuild: error: Could not resolve package dependencies:
  failed downloading 'https://github.com/getsentry/sentry-cocoa/releases/download/8.52.1/Sentry.xcframework.zip' which is required by binary target 'Sentry': downloadError("Could not connect to the server.")
  failed downloading 'https://storage.mds.yandex.net/get-appmetrica-mobile-sdk/175948/YandexMobileMetrica-4.5.2-ios-spm-4cf9781b-4e3e-4674-bbb3-5ab28cc9869a.zip' which is required by binary target 'YandexMobileMetrica': downloadError("Could not connect to the server.")
  failed downloading 'https://github.com/getsentry/sentry-cocoa/releases/download/8.52.1/Sentry-Dynamic.xcframework.zip' which is required by binary target 'Sentry-Dynamic': downloadError("Could not connect to the server.")
  failed downloading 'https://storage.mds.yandex.net/get-appmetrica-mobile-sdk/50347/YandexMobileMetricaCrashes-4.5.2-ios-spm-3ac18632-911c-404d-8f4d-4d2a496ee5b7.zip' which is required by binary target 'YandexMobileMetricaCrashes': downloadError("Could not connect to the server.")
  fatalError

环境细节

  • 已配置cntlm本地代理(端口8081)连接公网,SwiftPM可正常克隆非二进制依赖仓库
  • 已设置以下环境变量:
HTTPS_PROXY=http://127.0.0.1:8081
HTTP_PROXY=http://127.0.0.1:8081
all_proxy=http://127.0.0.1:8081
http_proxy=http://127.0.0.1:8081
https_proxy=http://127.0.0.1:8081
  • cURL可正常下载上述错误中的4个zip文件,但手动将归档文件放入以下目录无效:
$HOME/Library/Developer/Xcode/DerivedData/SomeApp-.../SourcePackages/artifacts/sentry-cocoa/Sentry
$HOME/Library/Developer/Xcode/DerivedData/SomeApp-.../SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic
$HOME/Library/Developer/Xcode/DerivedData/SomeApp-.../SourcePackages/artifacts/metrica-sdk-ios/YandexMobileMetrica
$HOME/Library/Developer/Xcode/DerivedData/SomeApp-.../SourcePackages/artifacts/metrica-sdk-ios/YandexMobileMetricaCrashes
  • 推测SwiftPM的SwiftNIO HTTPClient未读取代理环境变量,导致未走代理
  • 工作环境为共享macOS GitLab Runner,无sudo权限且无法SSH登录调试

可行解决方法

方法1:通过xcodebuild显式传递代理参数给SwiftPM

SwiftPM支持通过-Xswiftpm参数直接指定代理,修改构建命令如下:

XCODE_OPTIONS="-scmProvider system -resolvePackageDependencies"
SWIFTPM_PROXY_FLAGS="-Xswiftpm -http-proxy=http://127.0.0.1:8081 -Xswiftpm -https-proxy=http://127.0.0.1:8081"

xcodebuild clean $XCODE_OPTIONS $SWIFTPM_PROXY_FLAGS -workspace $WORKSPACE -scheme $SCHEME

注意:移除-disablePackageRepositoryCache,让SwiftPM优先使用缓存。

方法2:将手动下载的二进制包放入SwiftPM全局缓存目录

SwiftPM的全局缓存路径为$HOME/Library/Caches/org.swift.swiftpm/artifacts/,按以下步骤操作:

  1. 用curl下载所有需要的zip文件
  2. 为每个依赖创建对应版本的目录:
    $HOME/Library/Caches/org.swift.swiftpm/artifacts/sentry-cocoa/Sentry/8.52.1/
    $HOME/Library/Caches/org.swift.swiftpm/artifacts/sentry-cocoa/Sentry-Dynamic/8.52.1/
    $HOME/Library/Caches/org.swift.swiftpm/artifacts/metrica-sdk-ios/YandexMobileMetrica/4.5.2/
    $HOME/Library/Caches/org.swift.swiftpm/artifacts/metrica-sdk-ios/YandexMobileMetricaCrashes/4.5.2/
    
  3. 将对应的zip文件放入上述目录,确保文件名与错误信息中的URL文件名完全一致
  4. 执行xcodebuild时不添加-disablePackageRepositoryCache参数

方法3:修改项目依赖配置为本地引用(若有权限修改项目)

如果可以修改项目配置,将远程二进制依赖替换为本地文件:

  1. 下载并解压xcframework到项目目录下的Dependencies文件夹
  2. 通过Xcode的「File → Add Packages...」移除远程依赖,改为添加本地xcframework(直接拖入项目,设置为「Embed & Sign」)
  3. 若项目使用Package.swift,修改依赖配置:
    .binaryTarget(
        name: "Sentry",
        path: "./Dependencies/Sentry.xcframework"
    ),
    

方法4:配置GitLab Runner全局代理环境变量

如果有权限修改GitLab Runner配置,在Runner的config.toml中添加代理变量:

[[runners]]
  environment = [
    "HTTP_PROXY=http://127.0.0.1:8081",
    "HTTPS_PROXY=http://127.0.0.1:8081",
    "NO_PROXY=localhost,127.0.0.1"
  ]

这种方式能确保所有Runner任务继承代理配置,覆盖SwiftPM的环境变量读取问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 21:34:57