skip to Main Content

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

  1. Clone my app from GitHub
git clone [email protected]:fujidaiti/xcode-build-test.git
  1. 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.

  1. Clone, again
git clone [email protected]:fujidaiti/xcode-build-test.git
  1. Open the project with Xcode
open xcode-build-test/xcode-build-test.xcodeproj/

It will automatically begin resolving package dependencies and should succeed.

enter image description here

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

2

Answers


  1. Maybe try changing what ever is referencing https://github.com/kareman/SwiftShell#others/info/refs / https://github.com/kareman/SwiftShell#others into https://github.com/kareman/SwiftShell ?

    Login or Signup to reply.
  2. The problem is because of the package URL which is given in your project as

    https://github.com/kareman/SwiftShell#others

    The #others bit on the end is the issue, since xcodebuild doesn’t understand that. FWIW #others is an in-page link to a section in the readme file.

    I was able to fix it by modifying two files* in the project.

    xcode-build-test/xcode-build-test.xcodeproj/project.pbxproj
    xcode-build-test/xcode-build-test.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
    
    

    If you just find #others in both those files and remove it wherever it appears as part of the repository URL, you’ll find xcodebuild will successfully resolve the dependency.

    Whoever pasted the link into the Xcode project probably copied it from the address bar after having clicked on the link in the contents of the readme file. I find it good practice to always use the link provided by the code button for cloning the repo.

    *strictly speaking, you only need to fix project.pbxproj. You still get an diagnostic about the #others thing but it won’t stop the package from being resolved correctly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search