'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?
Solution 1:[1]
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:
In Finder, tap Shift+Cmd+. to reveal hidden files and folders.
The Package.resolved file is inside your .xcodeproj directory at [appName].xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Right click on .xcodeproj and project.xcworkspace to show package contents.
Move the Package.resolved file to the bin, and then empty the bin.
Reopen Xcode and open your project again. This gave me another error: the package at '/' cannot be accessed (Couldn’t read '4.5.0':
In Xcode, File / Packages / Reset package caches. The Swift Package Manager starts working on this.
Rebuild the project. The error had gone and my project rebuilt successfully.
Good luck!
Solution 2:[2]
Just did have the same problem after merging updates. And for me helped to deleting Package.resolved
file.
Solution 3:[3]
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 the file to continue: unsupported schema version 2
It meant the Xcode version of the CI didn't support that schema format. Upgrading it to match our development environment fixed the issue.
Solution 4:[4]
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.
Solution 5:[5]
I found this answer on forums.swift.org and it worked for me:
- Kill xcode
- Then completely remove the derived data directory (empty trash just to be absolutely sure).
- Restart Xcode
- Reset Swift package cache
Solution 6:[6]
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.
Solution 7:[7]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | konekoya |
Solution 2 | Sangsom |
Solution 3 | GoRoS |
Solution 4 | a.negovskiy |
Solution 5 | Maxwell |
Solution 6 | Nico S. |
Solution 7 | AVDCH |