I have a build error saying that all my SPM packages are missing. I decided to remove and re-add each package to the project, but each attempt at adding a package gives me the following error:

Package.resolved file is corrupted or malformed; fix or delete the file to continue

I've tried deleting the Package.resolved file and letting it regenerate (it didn't), but I get the same error message. Any ideas on how to fix this?

enter image description here

13

Best Answer


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.

Just to add another valid scenario, I got the same error on the CI with a little bit more detail:

Package.resolved file is corrupted or malformed; fix or delete thefile to continue: unsupported schema version 2

It meant the Xcode version of the CI didn't support that schema format.

Updating the Xcode version to match our development environment fixed the issue.

Just did have the same problem after merging updates. And for me helped to deleting Package.resolved file.

When using CocoaPods and SwiftPackageManager in a project together there are two Package.resolved files. One is in YourProj.xcworkspace and the other is in YourProj.xcproj -> project.xcworkspace. I had to delete both and then it worked again.

Also this issue may be caused by the fact that project opened from .xcworkspace instead of .xcodeproj file.We transitioned to SPM from CocoaPods and old .xcworkspace messed things up.

I found this answer on forums.swift.org and it worked for me:

  1. Kill xcode
  2. Then completely remove the derived data directory (empty trash just to be absolutely sure).
  3. Restart Xcode
  4. Reset Swift package cache

reason of the issue is that Package.resolved file is corrupted.you need delete the disable package and Package.resolved.

you could not find the Package.resolved in Finder,you should select it in the project.the detail as follow:

  1. open the .xcodeproj or .xcworkspace right click to show the content
  2. right click to show content of the project.xcworkspace
  3. open The xcshareddata/swiftpm,you should find the Package.resolved
  4. delete the file then re-add the package

The accepted answer works but finding it was baffling.

For people who looked at the accepted answer but can't where it's at, look at the comment underneath by @Andres Canella: project.xcworkspace/xcshareddata/swiftpm/Package.resolved

1- Close Xcode

2- Open your project folder then right click on the white project icon and select Show Package Contents

enter image description here

enter image description here

3- Open the xcshareddata folder, then open the swiftpm folder, then open the configuration folder, you should then see the Package.resolved file, just delete it.

enter image description here

I join the above and would like to supplement (or rather simplify) this procedure a little, you can not close xcode and do the same, while the Package.resolved file will automatically be added to the swiftpm folder, then you just update the pods.

Make sure the dependency graph is in good shape. Xcode is terribly bad at identifying and reporting problems with version conflicts.

None of these worked for me because there was a specific package that was corrupted and needed to be removed.

I removed it by opening Xcode and tapping on the project. Selecting the main project file and tapping the Package Dependencies tab. Here I was able to select the corrupted package and remove it from the project.

Then I proceed to delete the DerivedData folder from my project folder and then I followed the steps mention by Andrew

My internet connection got lost in the middle of downloading the dependencies and when I started xcode back up the file was corrupted in the workspace and there was no corresponding swiftPM folder in the xcode project package. Deleting the workspace spm allowed me to realize that one specific package wasn't being fetched and errored out the rest of the dependencies. I later found out that the library required a min version of xcode and i had to update in order for the package to download. The workspace I was building was made from another developer and I pulled it down from a repo.

There is no need to commit Package.resolved to the project git-repo, it can safely be added to .gitignore (remove the file from git, if it's already added.)

When adding a package to a project, set an acceptable update policy (branch, point release, major release etc.) in Package.swift. Depending on your requirements for each package.

All builds will generate Package.resolved.

This will allow a wider range of macOS/XCode instances to build the project. Allowing newer versions to avoid breaking things unnecessariliy.