85

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
Maxwell
  • 6,532
  • 4
  • 37
  • 55

13 Answers13

203

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Andrew Boswell
  • 2,054
  • 1
  • 4
  • 5
  • 5
    You are more than welcome to add a link to your web site to your profile, but it definitely does not belong in individual answers (unless the link actually contributes to the substance of the answer somehow, which clearly it did not do here). See also [promotion guideline](/help/promotion) – tripleee Sep 30 '21 at 09:15
  • I found this happens when switching back to v13.2.1 from a beta version. For me there are two steps: 1) delete the Package.resolved file and 2) Reset package caches. That does the trick. – Kim Mar 05 '22 at 09:46
  • How to find Package.resolved file? I am unable to find. Please help me. – Ashu Mar 06 '22 at 05:44
  • for me, the file is located at: /pathToMyProject/MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm – Kim Mar 15 '22 at 19:49
  • 14
    I found it in my workspace: project.xcworkspace/xcshareddata/swiftpm/Package.resolved – Andres Canella Mar 22 '22 at 17:41
  • 7
    Found it in the workspace too. I think if you're using cocoapods, the file will be located in the workspace not `xcodeproj` – Joshua Apr 01 '22 at 03:38
  • 3
    Another issue I encountered was that if Xcode was open it would instantly re-create the file and it still had the issue. Closing Xcode and then deleting fixed this. – Andres Canella Apr 04 '22 at 16:35
  • I was deleting file only in xcodeproj, but had to remove from xcworkspace also. – Ammar Mujeeb May 22 '22 at 12:07
  • "In Finder, tap Shift+Cmd+. to reveal hidden files and folders." Nothing happened when I did this. Actually it just made my text larger... – ScottyBlades Aug 04 '22 at 08:01
22

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.

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
GoRoS
  • 5,183
  • 2
  • 43
  • 66
  • 1
    how do you update the schema format or you meant update Xcode? – Nat Serrano May 27 '22 at 02:32
  • 4
    I meant upgrading XCode. Only the latest version knows hot to handle new schema versions (and most likely old ones being backwards compatible). – GoRoS May 27 '22 at 05:45
  • 1
    @GoRoS This is the command that runs in my CI right before I get this error `/Applications/Xcode_13.2.1.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies -scheme "xxx (Production)" -project ./xxx.xcodeproj`. I am unsure what to do here about it. I even tried to remove the Package.resolved from gitignore but that didn't change anything. – Tarek Jun 14 '22 at 23:11
  • 2
    @Tarek try to update Xcode to 13.4.1 or above and launch the same cmd with that version. That should support the second version of the schema. – GoRoS Jun 15 '22 at 07:47
  • 3
    @GoRoS That worked; thank you! I had to use `macos-12` instead of `macos-latest` to get `13.4.1` to work. – Tarek Jun 15 '22 at 21:39
  • Can confirm, switching from `macos-latest` to `macos-12` was the fix. Too bad, you'd think `latest` would be bundled with a more recent version of Xcode. – Justin Hammond Jul 27 '22 at 22:51
10

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

Sangsom
  • 373
  • 5
  • 9
10

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.

Nico S.
  • 3,056
  • 1
  • 30
  • 64
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.

3

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
Maxwell
  • 6,532
  • 4
  • 37
  • 55
3

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
maoyu
  • 31
  • 1
1

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.

AVDCH
  • 11
  • 1
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 04:14
1

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

Shengchalover
  • 614
  • 5
  • 10
1

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

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0

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

Markinson
  • 857
  • 1
  • 7
  • 13
0

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.

bubmacbub
  • 11
  • 3
0

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.

ocodo
  • 29,401
  • 18
  • 105
  • 117