Cannot Resolve Swift Packages After 15Th March 2022 in Xcode

Xcode 13.2.1 unable to resolve Swift Package Manager

I just spent two days on this same issue, and finally got my rather long list of packages to resolve and build. I just can't believe Apple can't fix this. If we could just update one package at a time we could slowly get everything to work. In any case, I just made notes to my team of what I did to finally get all packages to resolve:


If Xcode struggles to resolve them, the solution is complicated and must often be done multiple times (Xcode 13.2.1):

  • close the project
  • quit Xcode
  • delete every folder in the Derived folders, then in Finder delete Trash
  • cd to the folder containing the MyProject.xcodeproj and run:
    xcodebuild -resolvePackageDependencies -project MyProject.xcodeproj -scheme MyScheme -platform="iOS, name:'Any iOS Device'"
  • open Xcode
  • open the project

Some projects may not resolve or have errors (little red "x"s on the right side). Not good but may be solvable:

  • use Xcode "File" -> "Packages" -> "Resolve Packages"
  • alternately, close the project, then reopen it.

You will probably get some warnings when running xcode build, I get:

--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:xxx-xxx }
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
...

Once you get to a stable position, with no errors and all packages showing version numbers, you should be good for the long haul.

IMPORTANT: occasionally you need to update the minimum version shown in the Project -> Package Dependencies, to reflect the
existing Package release (which you may see from the left Xcode panel, or by visiting the Packages github site. If they are too
old you may have problems resolving after you wipe the Derived Folder (for some other reason, maybe Package Format changed?)

Local Swift Packages Stopped Working in Xcode 13

Removing package references from workspace and re-adding them (by simple drag-n-drop from Finder) resolved the problem.

I even didn't need to reconfigure corresponding schemes, or re-adding dependencies in targets.

Package.resolved file is corrupted or malformed

I tried the solution suggested by Maxwell above but it didn't resolve the problem for me.

The error appeared with Xcode 12 but upgrading to Xcode 13 didn't fix it either.

Instead, I decided to take Xcode at its word and delete the Package.resolved file. But where is it? I did this:

  1. In Finder, tap Shift+Cmd+. to reveal hidden files and folders.

  2. The Package.resolved file is inside your .xcodeproj directory at [appName].xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

  3. Right click on .xcodeproj and project.xcworkspace to show package contents.

  4. Move the Package.resolved file to the bin, and then empty the bin.

  5. Reopen Xcode and open your project again. This gave me another error:
    the package at '/' cannot be accessed (Couldn’t read '4.5.0':

  6. In Xcode, File / Packages / Reset package caches.
    The Swift Package Manager starts working on this.

  7. Rebuild the project. The error had gone and my project rebuilt successfully.

Good luck!



Related Topics



Leave a reply



Submit