xcode 无法调试嵌入在 Objective-C 应用程序中的 Swift 模块/框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39467654/
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
Cannot debug Swift module/framework embedded in Objective-C app
提问by Richard Stelling
Alternative titles (to aid searching)
- Cannot debug Swift 2.3 framework linked to an Objective-C app in Xcode 8
error in auto-import: failed to get module 'XYZ' from AST context
Xcode 8- Xcode 8 cannot debug Swift framework
warning: Swift error in module <XYZ>
- Workaround for; Xcode Debugger cannot debug apps written in Objective-C only but that link against frameworks written in Swift only. (28312362)
替代标题(以帮助搜索)
- 无法调试链接到 Xcode 8 中的 Objective-C 应用程序的 Swift 2.3 框架
error in auto-import: failed to get module 'XYZ' from AST context
Xcode 8- Xcode 8 无法调试 Swift 框架
warning: Swift error in module <XYZ>
- 解决方法;Xcode Debugger 不能调试仅用 Objective-C 编写的应用程序,但只能与用 Swift 编写的框架链接。(28312362)
I have an app written in Objective-C that links against some modules (frameworks) written in Swift 2.x.
我有一个用 Objective-C 编写的应用程序,它链接到一些用 Swift 2.x 编写的模块(框架)。
Question
题
Everything (debugging etc.) works fine in xcode7, however when moving to xcode8and updating the modules to use swift2.3I was unable to debug the modules.
一切(调试等)在xcode7 中都可以正常工作,但是当移动到xcode8并更新模块以使用swift2.3 时,我无法调试模块。
LLDB reported these errors:
LLDB 报告了这些错误:
warning: Swift error in module XYZ.
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'ABC' from AST context
This does not happen if I link the modules to an app built in Swift 2.3.
如果我将模块链接到内置于 Swift 2.3 的应用程序,则不会发生这种情况。
采纳答案by Richard Stelling
tl:dr
电话:博士
Add a user defined setting under "Build Settings" for your app target.
在“构建设置”下为您的应用程序目标添加用户定义的设置。
SWIFT_VERSION = 2.3
SWIFT_VERSION = 2.3
More Info
更多信息
I'm unsure if this is an Xcode 8 bug or if it's Apple policy (to try an force developers to Swift 3.0?). But... by default Xcode 8 installs the Swift 3.0 versions of the standard Swift runtime libraries.
我不确定这是 Xcode 8 错误还是 Apple 政策(尝试强制开发人员使用 Swift 3.0?)。但是……默认情况下,Xcode 8 安装标准 Swift 运行时库的 Swift 3.0 版本。
When it comes to debugging with LLDM the Swift 2.3 modules fail to load (in to the Swift 3.0 runtime).
在使用 LLDM 进行调试时,Swift 2.3 模块无法加载(进入 Swift 3.0 运行时)。
Forcing the app to use Swift 2.3 (or legacy Swift as Apple call it), fixes the issue.
强制应用程序使用 Swift 2.3(或 Apple 称其为旧版 Swift),解决了该问题。
Swift apps have this setting exposed by Xcode but you have to manually add it for an Objective-C app.
Swift 应用程序通过 Xcode 公开了此设置,但您必须为 Objective-C 应用程序手动添加它。
Further Advice
进一步的建议
Port your Swift 2.3 code to Swift 3.0 as soon as possible, Apple won't support 2.x for very long.
尽快将您的 Swift 2.3 代码移植到 Swift 3.0,Apple 不会长时间支持 2.x。
回答by Tim Friedland
For me it was just as simple as it was painful and time consuming:
对我来说,这既简单又痛苦又耗时:
import SDWebImage
was the PROBLEM,
because one of the frameworks had the SDWebImage already packed in it(and I couldn't see it), and that framework happened to be Objective-C, and the app was Swift.
I also added the SDWebImage to the project, because I use it in the classes I write, and that what created the mess the Xcode debugger couldn't deal with.
So basically, make sure you don't have ANYTHING duplicated in ANY way, I'd check for common things like SDWebImage for example.
import SDWebImage
是问题,因为其中一个框架已经将 SDWebImage 打包在其中(我看不到它),而该框架恰好是 Objective-C,而应用程序是 Swift。我还在项目中添加了 SDWebImage,因为我在我编写的类中使用了它,这造成了 Xcode 调试器无法处理的混乱。所以基本上,请确保您没有以任何方式复制任何内容,例如,我会检查 SDWebImage 之类的常见内容。
回答by Suresh Kansujiya
use fr vinstead pofor debugging
使用fr v代替po进行调试
For more debugging https://www.codeproject.com/Articles/1181358/Debugging-with-Xcode
更多调试 https://www.codeproject.com/Articles/1181358/Debugging-with-Xcode
回答by fredericouimet
I discussed this issue with an Apple engineer named Sean at WWDC 2017.
我在 WWDC 2017 上与一位名叫 Sean 的 Apple 工程师讨论了这个问题。
My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.
我的团队花了数周时间试图解决这个问题,结果发现它是 Apple 编译器上的一个错误,这是我们自己永远无法解决的。此外,它有一个非常简单的解决方法。
There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.
编译标志从框架和项目中聚合的方式碰巧存在一个错误,而“纯 Objective-C”项目“激活”了它。
Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c anymore (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).
解决方案:在您的 Objective-C 项目中添加一个单独的空 Swift 文件(“Whatever.swift”,或其他),使其不再是纯目标-c(new->file->Swift 文件,不要创建桥接头。该文件将只包含 Foundation 的导入)。
And that's it. Problem solved.
就是这样。问题解决了。
回答by Chamira Fernando
In my case, I had to remove Objective-C Bridging header
from build settings file. My Bridging header file did not do anything.. so it was okay.
就我而言,我不得不Objective-C Bridging header
从构建设置文件中删除。我的桥接头文件没有做任何事情..所以没关系。
回答by Jason Moore
I ran into the error in auto-import: failed to get module 'XYZ' from AST context
message while attempting to debug in an 9.3 simulator. Switching to a 10.2 simulator resolved the issue.
我error in auto-import: failed to get module 'XYZ' from AST context
在 9.3 模拟器中尝试调试时遇到了该消息。切换到 10.2 模拟器解决了这个问题。
回答by Austin
I ran into this when building a framework with Carthage. Trying to debug would print the error, which referenced an Obj-C framework dependency.
我在用 Carthage 构建框架时遇到了这个问题。尝试调试会打印错误,该错误引用了 Obj-C 框架依赖项。
I found this blog postwhich suggested adding a the following user-defined build setting to my project:
我发现这篇博客文章建议在我的项目中添加以下用户定义的构建设置:
For Debug: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = NO
对于调试: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = NO
For Release: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = YES
发布: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = YES
This fixed the issue for me.
这为我解决了这个问题。
回答by saltwat5r
Try to restart Xcode. In my case it resolved an issue.
尝试重新启动 Xcode。就我而言,它解决了一个问题。
回答by mbonness
In my case there was a compiler error in the "C" code which was reported in LLDB, after fixing the error LLDB started working again.
在我的情况下,LLDB 中报告的“C”代码中有一个编译器错误,在修复错误后,LLDB 再次开始工作。
回答by micmdk
As suggested by Tim https://stackoverflow.com/a/41876400/1840269the root cause to our problem was a matter of duplicates.
正如 Tim https://stackoverflow.com/a/41876400/1840269所建议的,我们问题的根本原因是重复问题。
We had a obj-c wrapper category for SDWebImage that was used from both obj-c and Swift. When Importing the category from Swift everything blew up because of redefinition/duplicate import since the SDWebImage pod already exposed it self as a Swift module.
我们有一个用于 SDWebImage 的 obj-c 包装器类别,在 obj-c 和 Swift 中都使用过。当从 Swift 导入类别时,一切都因为重新定义/重复导入而爆炸,因为 SDWebImage pod 已经将它自己暴露为 Swift 模块。
The solution? We re-implemented the obj-c category as a Swift extension - and kept using it from both Swift and obj-c by adding @objc
in front of the extension and importing the #import "product-Swift.h"
file from obj-c.
解决方案?我们将 obj-c 类别重新实现为 Swift 扩展 - 并通过@objc
在扩展前添加并#import "product-Swift.h"
从 obj-c导入文件来继续从 Swift 和 obj-c 中使用它。
And maybe start with checking: https://developer.apple.com/library/content/qa/qa1947/_index.html.
也许从检查开始:https://developer.apple.com/library/content/qa/qa1947/_index.html。