xcodeswift-package-manager

Package.resolved file is corrupted or malformed


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


Solution

  • 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.