25

I recently enabled modules in my Xcode project build settings ("Enable Modules (C and Objective-C)") and now I frequently get the below build error. It works the next time I build (without any changes) but it is annoying because it happens very often (several times an hour).

fatal error: malformed or corrupted AST file: 'could not find file '/Users/mpv/dev/project/Crashlytics.framework/Headers/Crashlytics.h' referenced by AST file' note: after modifying system headers, please delete the module cache at '/Users/mpv/Library/Developer/Xcode/DerivedData/ModuleCache/M5WJ0FYE7N06'

Crashlytics recommended removing Crashlytics.h from the precompiled header file (.pch) and importing directly in each source file that needs it. This greatly reduces the problem but I still occasionally get a Crashlytics.h file not found error when building.

fatal error: 'Crashlytics/Crashlytics.h' file not found
#import <Crashlytics/Crashlytics.h>
Mike Vosseller
  • 4,097
  • 5
  • 26
  • 28

2 Answers2

63

First, try going to Product -> Clean menu in Xcode. Then rebuild when it finishes.

If that doesn't work, go to your [Name]-Prefix.pch file in the Supporting Files folder, and delete the #import line. Build. It will have errors, it's ok, now start typing it again and make sure to select the right choice from the drop-down suggest menu so it auto-fills the rest of the line for you. (This step worked for me).

Good luck! Love it when Xcode goes weird like this :)

Alex the Ukrainian
  • 4,528
  • 3
  • 24
  • 25
  • I got this when trying to run a trivial Unit test on a project where I'd just changed all the "int" to "NSInteger" or "NSUInteger" as appropriate. Xcode5 kept saying "delete module directory BLAH" but that had no effect - it's a bug :(. Doing a Clean fixed it. – Adam Dec 29 '13 at 20:54
  • Don't remember specifics, @binzhang, but I think I saw which line crashes, so I commented it out. Rebuild didn't work, so I added it again, this time with auto-complete (accident). It worked. So there :P – Alex the Ukrainian Jan 29 '14 at 06:34
  • 1
    Thank you! This worked for me even though deleting derived data didn't. I wouldn't have expected that. – Dave Batton Feb 10 '14 at 22:06
  • This worked like a charm! The solution over here: http://stackoverflow.com/questions/20984166/fatal-error-malformed-or-corrupted-ast-file-xcode did not work for me. – Beta May 03 '14 at 03:06
  • Removing the offending framework from my pch fixed the issue. Thanks. – logancautrell May 29 '14 at 14:22
  • To say I was skeptical would be an understatement. Great find. – Justin Aug 25 '14 at 20:43
  • Had the same problem with Xcode 6.4. Reinstalling it did not work, reinstalling OS X from a time machine backup neither, but forcing the rebuild by changing the .pch file contents solved it. Thanks at lot! – Pegolon Sep 11 '15 at 19:54
  • This is the life savior – damithH Apr 11 '17 at 06:21
0

I hit this issue after updating my version of Xcode via the Mac App Store.

After updating Xcode, the xcode-select Command Line Tools version of Xcode was still set to the old version. This was creating some kind of mismatch in xcodebuild.

I solved the issue like so:

  1. Xcode > Preferences > Command Line Tools. Select the newest Xcode version.
  2. Quit Xcode
  3. Delete the ~/Library/Developer/Xcode/DerivedData directory.
  4. Run build script again. Success!

For SEO purposes, when I was hitting this issue I saw the following errors:

error: InputFile /Users/user/source/Your-PCH-Prefix.pch 0 1406772618 191 33188... malformed line 9; 'InputFile' should have exactly five arguments

Also:

xcodebuild[53039:5503] stream error: stream error at offset 29: created by an unsupported XCDependencyGraph build
xcodebuild[53039:4e0b] stream error: stream error at offset 29: created by an unsupported XCDependencyGraph build
** BUILD FAILED **


The following build commands failed:
    Write auxiliary files
    MappingModelCompile 
pkamb
  • 33,281
  • 23
  • 160
  • 191