xcode Swift 在为此模块构建 ast 上下文时出现致命错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30946434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift had fatal errors constructing the ast context for this module
提问by Fook
I upgraded my project to Swift 2 in Xcode 7 beta (7A120f) and get this error when trying to po selfat the lldb prompt:
我在 Xcode 7 beta (7A120f) 中将我的项目升级到 Swift 2 并在 lldb 提示符下尝试po self时收到此错误:
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.
警告:模块 myApp 中的 Swift 错误:
Swift 在为此模块构建 ast 上下文时出现致命错误:无法为“UIKit”加载底层模块 来自该模块的调试信息在调试器中将不可用。
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
- 清除派生数据
- 产品 > 清洁
- 重启xcode
- 重启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.
我能够创建一个新项目并在其中查看调试输出,所以这可能与 xcode 如何迁移我的项目有关。
What is the ast context and how can I correct it?
什么是 ast 上下文,我该如何纠正它?
Edit:ast is 'Abstract Syntax Tree'. Still no idea how to fix it though.
编辑:ast 是“抽象语法树”。仍然不知道如何修复它。
采纳答案by Fook
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.
为了解决这个问题,我手动将所有文件和设置迁移到新的 xcode 项目。没有其他工作。可能有更好的修复方法,但我不能再花时间寻找它了。
回答by phatblat
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
对象时吐出的错误突出显示了这个问题:
(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.
所述Crashlytics.h
伞头在Crashlytics.framework
被导入Fabric/FABAttributes.h
,其不是Crashlytics模块的一部分(即,不是在它的module.modulemap
)。这是使用 CocoaPods 安装的 Crashlytics 3.1.0。
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.
我无法理解为什么 Xcode 7 将此视为致命错误(这只是 6 中的警告)。在 Xcode 6 中,您可以通过CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES
在应用程序目标中启用“在框架模块中允许非模块化包含”( ) 构建设置来解决这种“非模块化标头包含”问题。
I've had no luck getting the Xcode 7 betas to honor the above flag (rdar://22044453<-- please dup).
我没有运气让 Xcode 7 betas 兑现上述标志(rdar://22044453<-- 请重复)。
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.
我发现让调试器工作的唯一解决方案是删除 Crashlytics pod。我注释掉 Crashlytics 和 Fabric pod,运行pod install
,恢复调试,然后在发布之前重新安装 pod。
I really hope this is fixed in Xcode 7 by the time it comes out of beta.
我真的希望在 Xcode 7 出测试版时能在 Xcode 7 中解决这个问题。
回答by Dmitry
Check your bridging header and if you have
检查您的桥接头,如果您有
@import Crashlytics;
@import Crashlytics;
(or any other frameworks that cause the error. In my case it was GoogleMobileAds
)
(或任何其他导致错误的框架。在我的情况下是GoogleMobileAds
)
try replacing with
尝试替换为
#import <Crashlytics/Crashlytics.h>
#import <Crashlytics/Crashlytics.h>
回答by got2b_ae
I had the same issue. In the most cases this issues appears when you use objective-c frameworks or libraries in Swift project.
我遇到过同样的问题。大多数情况下,当您在 Swift 项目中使用 Objective-c 框架或库时,会出现此问题。
The issue was fixed by importing objective-c frameworks or libraries in Bridging-Header only.
该问题已通过仅在 Bridging-Header 中导入 Objective-c 框架或库来解决。
#import <SampleFramework/SampleFramework.h>
and remove all imports of this framework from Swift files
并从 Swift 文件中删除此框架的所有导入
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.
确保您对项目中的所有 Objective-c 框架或库都执行了此过程。
Hope this helps!
希望这可以帮助!