I'm encountering an issue where I can successfully build my Swift application using XCode, but when I try to build it using the "xcodebuild" command in the terminal, I'm facing build errors. It always seems to fail when resolving package dependencies. I want to build the project from the command line, but I don't know why this problem occurs or how to solve it...
Steps to reproduce this issue
Failure case
- Clone my app from GitHub
git clone git@github.com:fujidaiti/xcode-build-test.git
- Resolve the package dependencies
xcodebuild -resolvePackageDependencies -project xcode-build-test/xcode-build-test.xcodeproj/ -scheme xcode-build-test
Then an error should occur:
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?
Building the project will, of course, fail:
$ 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
Opening the project in Xcode should succeed.
- Clone, again
git clone git@github.com:fujidaiti/xcode-build-test.git
- Open the project with Xcode
open xcode-build-test/xcode-build-test.xcodeproj/
It will automatically begin resolving package dependencies and should succeed.
After that, we can successfully build the project with 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 **
Environment
- MacBook Air (M1, 2020)
- OS: 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