11

enter image description here

This error always happens whenever I add a new Package via Swift Package Manager in Xcode:

Cannot fetch library

I've already configured my GitHub Auth Token setting in Xcode and registered my GitHub account.

My macOS version is Monterey 12.1, my Xcode version is 13.1, my command-line tools are 13.1, and I'm using an M1 chipset Mac.

enter image description here

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71
iostaeha
  • 127
  • 1
  • 4
  • Welcome to stackoverflow! Please edit your question so that the error message is in the text instead of the image. This makes it more accessible and easier to find via search engines. Also your question contains some malformed markup code, please fix that. – laka Dec 19 '21 at 06:57

2 Answers2

3

Configure Dependency Rule

tl;dr

I encountered this issue today and managed to resolve the Package by changing the Dependency Rule from Branch -> master to Up to Next Major Version and checking their latest Release versions from GitHub.

Other Dependency Rules

We can also try changing from Branch to other rules depending on our application:

  1. Up to Next Major Version: Useful for getting the latest major stable release.
  2. Up to Next Minor Version: Useful for getting the very latest releases.
  3. Range of Versions: Useful for resolving dependencies specific to a particular dependency chain (careful configuration).
  4. Exact Version: Useful for pinning a version to a particular working release, or fork.
  5. Commit: Useful for pinning a Package to a commit rather than a release version.

Xcode SPM "Add Package" prompt

Xcode Add Package prompt

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71
0

I tried to simulate your problem, Xcode and command-line version are the same. I was able to add SnapKit into my project without problems. Try this workaround:

Project -> Package Dependencies -> + -> paste the link: https://github.com/SnapKit/SnapKit -> Dependency rule set to Up To Next Major -> Add Package.

It should add a new package. Currently in version 5.0.1 If you have still a problem, just click Add Anyway, build the project and send a screenshot of the error.

Juraj Macák
  • 149
  • 1
  • 1
  • 10
  • hi juraj, thx for your comment. I followed your solution, but didn't work for me – iostaeha Dec 12 '21 at 10:58
  • I added another screen shot. this error always happened in Derived Data. I did remove all Derived Data, but problem wasn't not solved – iostaeha Dec 12 '21 at 10:59
  • @iostaeha, Try to click Add Anyway and build project, you should see a more detailed error description. I faced a similar problem. If that workaround above doesn't work, try to right-click on the package in that Recently Used Packages list and choose Remove Package. Repeat workaround. – Juraj Macák Dec 12 '21 at 11:16
  • I clicked Add Anyway, and added error message screen shot in my question – iostaeha Dec 12 '21 at 11:31
  • Showing Recent Messages SnapKit https://github.com/SnapKit/SnapKit: An unknown error occurred. '/Users/haba/Library/Developer/Xcode/DerivedData/test-hegqkymdqggryneilomohsbixdou/SourcePackages/repositories/SnapKit-4cdad746' exists and is not an empty directory (-4) Fetching from https://github.com/SnapKit/SnapKit Resolving Package Graph Failed 2021/12/12 9:06 PM 0.8 seconds – iostaeha Dec 12 '21 at 12:07