Package.resolved file is corrupted or malformed
Asked Answered
A

16

97

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

Aggie answered 20/4, 2021 at 20:20 Comment(0)
V
245

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.

Varese answered 30/9, 2021 at 9:7 Comment(10)
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 guidelineAllopath
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.Strident
How to find Package.resolved file? I am unable to find. Please help me.Void
for me, the file is located at: /pathToMyProject/MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpmStrident
I found it in my workspace: project.xcworkspace/xcshareddata/swiftpm/Package.resolvedBurkett
Found it in the workspace too. I think if you're using cocoapods, the file will be located in the workspace not xcodeprojMillihenry
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.Burkett
I was deleting file only in xcodeproj, but had to remove from xcworkspace also.Hype
"In Finder, tap Shift+Cmd+. to reveal hidden files and folders." Nothing happened when I did this. Actually it just made my text larger...Groom
So decided to edit that Package.resolved file and sure enough, it WAS corrupt. You could tell because the JSON had "diff" merge-marks in it. Anyway, just edited/deleted the diff, saved, and was then able to add my new package.Duda
K
26

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.

Knotted answered 20/4, 2022 at 11:38 Comment(6)
how do you update the schema format or you meant update Xcode?Atal
I meant upgrading XCode. Only the latest version knows hot to handle new schema versions (and most likely old ones being backwards compatible).Knotted
@Knotted 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.Torrefy
@Torrefy 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.Knotted
@Knotted That worked; thank you! I had to use macos-12 instead of macos-latest to get 13.4.1 to work.Torrefy
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.Decencies
H
12

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.

Higgs answered 2/4, 2022 at 21:54 Comment(0)
P
10

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

Philender answered 18/8, 2021 at 8:24 Comment(3)
how? ------------Groom
Check the accepted answer for steps requiredPhilender
I noticed that after this comment. However, I couldn’t reveal the hidden files following those steps though anyway.Groom
P
7

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

Pyoid answered 23/1, 2023 at 12:16 Comment(0)
L
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.

Lheureux answered 17/8, 2021 at 7:28 Comment(0)
D
4

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
Disentail answered 19/8, 2022 at 0:42 Comment(1)
it's what i've done and it solved the issueChili
A
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
Aggie answered 20/4, 2021 at 21:7 Comment(1)
didn't help____Lonesome
Z
2

In my case, an issue was in my Xcode Cloud workflow. I was using a lower version of Xcode 15.1 in my Xcode Cloud workflow while my local version was Xcode 15.3.

I've changed the Xcode version in my workflows.

Zugzwang answered 12/4 at 14:56 Comment(0)
S
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.

Sylvanite answered 29/3, 2022 at 8:27 Comment(1)
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.Demos
N
1

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

Nomi answered 14/6, 2022 at 17:57 Comment(0)
N
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

Natascha answered 31/1, 2023 at 0:34 Comment(0)
D
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.

Dolph answered 5/4, 2023 at 19:30 Comment(0)
O
0

If the above solution did't worked even after deleting/renaming/modifying the package.resolved file. Try this solution.

Quit Xcode.

git restore "filepath"

This will restore the last committed version.

Overtake answered 5/10, 2023 at 12:54 Comment(0)
A
0

You can reload the packages in Xcode by following these steps:

  1. Open your project in Xcode.
  2. Go to the "File" menu in the top menu bar.
  3. Choose "Swift Packages" and then "Update to Latest Package Versions" or "Resolve Package Versions".

This will prompt Xcode to reload and update all the packages in your project and recreate the Package.resolved file.

If you prefer using the command line, you can use Swift Package Manager directly. Open the terminal and navigate to your project folder, then run the following command:

swift package update

This will update all the packages and recreate the Package.resolved file as well

Agueweed answered 29/3 at 20:43 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Loyceloyd
P
-4

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.

Piliform answered 23/8, 2023 at 3:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.