我遇到了一个问题,我可以使用XCode成功构建我的SWIFT应用程序,但当我try 在终端中使用"xcodeBuild"命令构建它时,我面临构建错误.在解析包依赖项时,它似乎总是失败.我想从命令行构建项目,但我不知道为什么会出现这个问题,也不知道如何解决它……
重现此问题的步骤
Failure case
- 从GitHub克隆我的应用程序
git clone git@github.com:fujidaiti/xcode-build-test.git
- 解析包依赖关系
xcodebuild -resolvePackageDependencies -project xcode-build-test/xcode-build-test.xcodeproj/ -scheme xcode-build-test
则应出现错误:
2023-05-31 15:55:11.778 xcodebuild[80462:1951627] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies -project xcode-build-test/xcode-build-test.xcodeproj/ -scheme xcode-build-test
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
Resolve Package Graph
Fetching from https://github.com/kareman/SwiftShell#others (cached)
skipping cache due to an error: Couldn’t fetch updates from remote repositories:
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?
Fetching from https://github.com/kareman/SwiftShell#others (cached)
skipping cache due to an error: Couldn’t fetch updates from remote repositories:
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?2023-05-31 15:55:14.411 xcodebuild[80462:1951627] Writing error result bundle to /var/folders/qb/wfmhbh3d6rdbp3z8lb8vl8zm0000gn/T/ResultBundle_2023-31-05_15-55-0014.xcresult
xcodebuild: error: Could not resolve package dependencies:
Failed to clone repository https://github.com/kareman/SwiftShell#others:
Cloning into bare repository '/Users/daichi/Library/Developer/Xcode/DerivedData/xcode-build-test-fvydfaqhyyxivzdsrdbbaxsykdxf/SourcePackages/repositories/SwiftShell-0eb504d5'...
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?
当然,建设该项目将失败:
$ xcodebuild -project xcode-build-test/xcode-build-test.xcodeproj -scheme xcode-build-test
2023-05-31 16:31:08.693 xcodebuild[82256:1980717] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project xcode-build-test/xcode-build-test.xcodeproj -scheme xcode-build-test
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
Resolve Package Graph
Fetching from https://github.com/kareman/SwiftShell#others (cached)
skipping cache due to an error: Couldn’t fetch updates from remote repositories:
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?
Fetching from https://github.com/kareman/SwiftShell#others (cached)
skipping cache due to an error: Couldn’t fetch updates from remote repositories:
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?2023-05-31 16:31:09.245 xcodebuild[82256:1980717] Writing error result bundle to /var/folders/qb/wfmhbh3d6rdbp3z8lb8vl8zm0000gn/T/ResultBundle_2023-31-05_16-31-0009.xcresult
xcodebuild: error: Could not resolve package dependencies:
Failed to clone repository https://github.com/kareman/SwiftShell#others:
Cloning into bare repository '/Users/daichi/Library/Developer/Xcode/DerivedData/xcode-build-test-fvydfaqhyyxivzdsrdbbaxsykdxf/SourcePackages/repositories/SwiftShell-0eb504d5'...
fatal: https://github.com/kareman/SwiftShell#others/info/refs not valid: could not determine hash algorithm; is this a git repository?
Success case
在Xcode中打开该项目应该会成功.
- 克隆,再一次
git clone git@github.com:fujidaiti/xcode-build-test.git
- 使用Xcode打开项目
open xcode-build-test/xcode-build-test.xcodeproj/
它将自动开始解析包依赖关系,并且应该会成功.
在此之后,我们可以使用xcodeBuild成功构建项目:
$ xcodebuild -project xcode-build-test/xcode-build-test.xcodeproj -scheme xcode-build-test
2023-05-31 16:12:45.885 xcodebuild[81087:1965576] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project xcode-build-test/xcode-build-test.xcodeproj -scheme xcode-build-test
...
RegisterWithLaunchServices /Users/daichi/Library/Developer/Xcode/DerivedData/xcode-build-test-fvydfaqhyyxivzdsrdbbaxsykdxf/Build/Products/Debug/xcode-build-test.app (in target 'xcode-build-test' from project 'xcode-build-test')
cd /Users/daichi/Dev/tmp/xcode-build-test
/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -f -R -trusted /Users/daichi/Library/Developer/Xcode/DerivedData/xcode-build-test-fvydfaqhyyxivzdsrdbbaxsykdxf/Build/Products/Debug/xcode-build-test.app
** BUILD SUCCEEDED **
环境
- MacBook Air(M1,2020)
- 操作系统:Ventura 13.4
- Xcode 14.3
$ xcodebuild -version
Xcode 14.3
Build version 14E222b
$xcode-select --version
xcode-select version 2397.
$ git --version
git version 2.39.0