43

I have a problem I don't know why did it happen in the first place but most probably because I've pressed move to trash to some system frameworks by mistake.

I got an error that says:

malformed or corrupted AST file: 'could not find file '/Users/username/myProject/QuartzCore.framework/Headers/CAMediaTiming.h' referenced by AST file'

I've tried to copy QuartzCore.framework in that Directory. It give me then a punch of new errors. Then if I remove the framework from the Dir. Everything will be good for the project till I make any code change. Then I would have to make the previous scenario again. It's very annoying now and I really need to fix this. Anyone?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Mohamed Emad Hegab
  • 2,665
  • 6
  • 39
  • 64

7 Answers7

99

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.

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • 4
    This has never worked for me. If "clean" fails, then deleting the moduleCache has no effect. Same on multiple projects, multiple setups. – Adam Feb 03 '14 at 15:08
  • 1
    @Adam For me I had to clean the project before deleting the module cache, then delete the module cache, and then CLEAN the project AGAIN after it was deleted. If I didn't clean before and after the error stayed in RAM or something and would then be re-written into the module cache immediately as if I had never deleted it. – Albert Renshaw Feb 03 '14 at 15:46
  • Xcode has long had major bugs where it overwrites data on your hard disk so long as Xcode is running. I've cleaned, quit, deleted, re-started, cleaned, etc ... no effect. – Adam Feb 03 '14 at 15:54
  • @Adam Ah! Sorry /: I wish you best of luck! This method worked for me (And I only got this error when I purchased a new mac)! Bookmark this and be sure to come back when you find a solution so you can edit it in to this! Good luck! – Albert Renshaw Feb 03 '14 at 17:09
  • @Adam Just had the problem happen again tonight and this time I was able to figure out what caused it... simulator created the malformed AST files for me, and I NEVER use simulator, but the cord holding my iPhone got bumped and it wiggled a little and disconnected (even though it didn't appear disconnected) switching Xcode over to simulator which gave me those mock .o errors that everyone gets all the time when you use frameworks that simulator can't handle (like displaying a camera)... then when switching back to my device I would get the AST error. – Albert Renshaw Feb 05 '14 at 03:34
  • @Adam All that said, I did my original solution and it wouldn't work... but once I did get it working I modified my answer above, please try the new steps (follow them closely!) Thanks :) – Albert Renshaw Feb 05 '14 at 03:34
  • 9
    All I needed to do was to clean the project and rebuilt. – Boon Sep 22 '14 at 19:01
  • Also, submit a bug report to apple. This has gone on for too long. – Joel Teply Jan 27 '15 at 22:39
  • I tried all these steps. even restarting the machine. no luck then I used to use xcodebuild commands its succeeded. – damithH Apr 07 '17 at 03:25
  • found similar problem with AST file. Could someone explain what AST file is, please? tried to google — nothing valuable – pash3r Jul 13 '22 at 11:14
10

In addition to all of the other "clean your build" answers, nothing was working for me until I emptied out the (highly undocumented!) /var/folders directory.

Apparently, this is a "miscellaneous caches" dir maintained by OS-X. I didn't even bother figuring out what were "the correct files"; I just cleaned out the entire directory.

...And now I can build again. Hooray! From terminal:

[sudo] rm -rf /var/folders/*

(Although I did it from Finder, via authentication.) (OS-X 10.9.latest)

Additional clue: I could build with XCode-6-beta, but got the goofy "corrupted AST file" error in XCode-5.

Olie
  • 24,597
  • 18
  • 99
  • 131
6

In my situation, all I needed to do was click Product > Clean, then build the project again. It succeeded. Hope this helps some others who run into the same situation.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
4

Hi all I got the same error because I have opened two projects at a time and drag and dropped frameworks from one project to another . After some time I realised that this is not a right way. I moved all frameworks which are dragged from another project to trash. Then clean and run in simulator everything is working fine.

Delete frameworks->again add frameworks->clean and run

I hope it will help someone

Narasimha Nallamsetty
  • 1,215
  • 14
  • 16
4

Personnaly, just one solution worked for me: In Xcode Go to Window -> Organizer Clic on the "delete" button near the "derived data" directory. Then Run again your project...

Daniel C.
  • 1,534
  • 1
  • 10
  • 5
  • This is the only thing that worked for me as well. I was unable to Analyze my project until i deleted the derived data, and this way is much easier then trying to go out and find it. – hoss Jul 14 '15 at 12:34
0

I just clean my project and re-build. Everything back to normal.

TPG
  • 2,811
  • 1
  • 31
  • 52
0

In my case, the error was happening because I had a corrupted .m file - it was one that had, somehow (not quite sure how) found its way into my project (I had Eclipse open at the same time and the corrupted file had some java code in it). To fix the problem, I cleaned my project, closed Xcode, deleted the erroneous .m file & re-opened Xcode. It then gave me a clang error due to the now missing .m file. I created a new, empty .m file with the same name and the project ran fine. Bit of a hack but it worked :-)

JanB
  • 904
  • 9
  • 14