Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift had fatal errors constructing the ast context for this module

Tags:

xcode

swift

I upgraded my project to Swift 2 in Xcode 7 beta (7A120f) and get this error when trying to po self at the lldb prompt:

warning: Swift error in module myApp:

Swift had fatal errors constructing the ast context for this module: cannot load underlying module for 'UIKit' Debug info from this module will be unavailable in the debugger.

I'm then left with a crippled debugger (no values). This happens regardless of where I place a breakpoint. I've tried:

  • clearing derived data
  • Product > Clean
  • restarting xcode
  • restarting mac

I'm able to create a new project and see debug output in it, so this probably has something to do with how my project was migrated by xcode.

What is the ast context and how can I correct it?

Edit: ast is 'Abstract Syntax Tree'. Still no idea how to fix it though.

like image 890
Fook Avatar asked Jun 19 '15 20:06

Fook


4 Answers

I'm having the same issue in my project. The error that lldb spits out when attempting to po an object highlights the issue:

(lldb)po fileURL
warning: Swift error in module <APP_NAME>:
    Swift had fatal errors constructing the ast context for this module: <module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/Crashlytics.h"
        ^
<APP_PATH>/Pods/Crashlytics/Crashlytics.framework/Headers/Crashlytics.h:10:9: error: include of non-modular header inside framework module 'Crashlytics'
#import <Fabric/FABAttributes.h>
        ^

The Crashlytics.h umbrella header in Crashlytics.framework is importing Fabric/FABAttributes.h, which is not part of the Crashlytics module (i.e. not in its module.modulemap). This is Crashlytics 3.1.0 installed using CocoaPods.

Why Xcode 7 treats this as a fatal error is beyond me (it was just a warning in 6). In Xcode 6 you could work around this sort of "non-modular header include" by enabling the "Allow Non-modular includes in Framework Modules" (CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES) build setting in your application target.

I've had no luck getting the Xcode 7 betas to honor the above flag (rdar://22044453 <-- please dup).

The only solution I've found to get the debugger working is to remove the Crashlytics pod. I comment out the Crashlytics and Fabric pods, run pod install, resume debugging and then reinstall the pods before a release.

I really hope this is fixed in Xcode 7 by the time it comes out of beta.

like image 69
phatblat Avatar answered Nov 18 '22 11:11

phatblat


Check your bridging header and if you have

@import Crashlytics;

(or any other frameworks that cause the error. In my case it was GoogleMobileAds)

try replacing with

#import <Crashlytics/Crashlytics.h>

like image 45
Dmitry Avatar answered Nov 18 '22 12:11

Dmitry


To fix this I manually migrated all my files and settings to a new xcode project. Nothing else worked. There is probably a better fix but I couldn't spend any more time looking for it.

like image 1
Fook Avatar answered Nov 18 '22 10:11

Fook


I had the same issue. In the most cases this issues appears when you use objective-c frameworks or libraries in Swift project.

The issue was fixed by importing objective-c frameworks or libraries in Bridging-Header only.

#import <SampleFramework/SampleFramework.h>

and remove all imports of this framework from Swift files

import SampleFramework // <-- Remove it

Then Clean and Build.

Make sure that you did this procedure for all objective-c frameworks or libraries in your projects.

Hope this helps!

like image 1
got2b_ae Avatar answered Nov 18 '22 11:11

got2b_ae