1

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 git@github.com: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 git@github.com: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
fuji
  • 45
  • 5
  • I can't reproduce the problem. I followed the first set of instructions and it successfully resolved the packages. The only difference is I ran it on an Intel Mac. – JeremyP May 31 '23 at 09:38
  • Could you try the same thing after removing the cache by `rm -rf ~/Library/Developer/Xcode/DerivedData/xcode-build-test-*`? – fuji May 31 '23 at 09:53
  • Unrelated but the version of xcode-select isn't very relevant, if anything you should use `xcode-select -p` to print the path of the directory that the Xcode command line tools uses (but I believe you already have that information from `xcodebuild -version`). – Joakim Danielson May 31 '23 at 10:29
  • You must have made some mistake when adding the package, when I removed and re-added it to the project I did not get an url that contained the hashtag but only `https://github.com/kareman/SwiftShell` – Joakim Danielson May 31 '23 at 10:48
  • @JoakimDanielson It worked, tanks! I blamed Xcode, but it was my mistake, haha – fuji May 31 '23 at 12:04
  • Same issue, this was my solution: https://stackoverflow.com/a/76529808/7019858 – AD1170 Jun 22 '23 at 08:34

2 Answers2

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 ?

  • Which file should I change, since it was auto generated when I installed that package using the swift package manager in Xcode? – fuji May 31 '23 at 09:41
  • @fuji https://i.imgur.com/kekY618.png in this image, it seems on line 588, there seems to be a `#others` try possible checking in this image to edit the link of the package? https://i.imgur.com/wK08tdl.png – Nash Equilibrium May 31 '23 at 10:03
1

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.

JeremyP
  • 84,577
  • 15
  • 123
  • 161