Fatal Error: Malformed or Corrupted Ast File - Xcode

Malformed or corrupted AST file

As requested:

What caused this error for me (after getting the new Xcode) was I would try to run a project in simulator (accidentally in simulator, I never use simulator), but I'd forget to select my device or my device would become unplugged without me noticing, and it will try to run in simulator... so I would get those classic ".o" file errors... Then I would switch back to my device and get corrupt AST files...


To CURE the problem... (Follow the steps below VERY closely!!!!!)

  1. Clean your project
  2. QUIT Xcode (CMD+Q)
  3. Run this Terminal Command:
    rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache/*
  4. Run this Terminal Command:
    rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/*
  5. Reopen Xcode
  6. MAKE SURE YOU HAVE YOUR DEVICE SELECTED AND NOT SIMULATOR
  7. CLEAN project (Yes, again)
  8. THEN build (to your device, not to simulator)...

Enjoy!

Note: After further experimentation I've found that the force-quitting of xCode is possibly not necessary.

Package.resolved file is corrupted or malformed

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.

Good luck!



Related Topics



Leave a reply



Submit