ios Swift 框架:未找到 Umbrella 标头“[...].h”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30355133/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:01:59  来源:igfitidea点击:

Swift Framework: Umbrella header '[...].h' not found

iosswiftios-frameworks

提问by Tim Bodeit

In a custom framework containing both Objective-Cand Swiftcode, the Swift compiler throws the following error:

在包含Objective-CSwift代码的自定义框架中,Swift 编译器会抛出以下错误:

[build_path]/unextended-module.modulemap:2:19: error: umbrella header 'bugtest.h' not found
  umbrella header "bugtest.h"
                  ^
<unknown>:0: error: could not build Objective-C module 'bugtest'

采纳答案by Tim Bodeit

This will happen, when the Always Search User Pathssetting is enabled for the Framework target.

Always Search User Paths为框架目标启用设置时,就会发生这种情况。

Setting it to Nowill resolve that error.

将其设置为No将解决该错误。

IMHO this is a bug in the Swift Compiler and I have filed a radar with Apple.
See rdar://21038443

恕我直言,这是 Swift 编译器中的一个错误,我已向 Apple 提交了一份雷达报告。
rdar://21038443

回答by arturgrigor

This usually happens after a project rename or something like that. The problem is that the umbrella header is no longer listed as a Publicheader. Check the attached image to see how to fix this.

这通常发生在项目重命名或类似的事情之后。问题是伞头不再列为公共头。检查附加的图像以了解如何解决此问题。

Fix

使固定

回答by Claude Houle

In Xcode 7 Beta, with Swift 2, it will also happen if your Framework Header is not declared as "Public"

在 Xcode 7 Beta 中,使用 Swift 2,如果您的 Framework Header 未声明为“Public”,也会发生这种情况

For instance, I had a Cocoa Touch Framework with a "Project" visibility for the header file, and the error "Umbrella Header ... not found" for all Swift files in my project, once I had the header "Public", the error went away

例如,我有一个 Cocoa Touch 框架,头文件的“项目”可见性,以及我项目中所有 Swift 文件的错误“Umbrella Header ... not found”,一旦我有标题“Public”,错误消失了

回答by Claus J?rgensen

There's 4 different ways this can happen, ignoring bugs in previous versions of Xcode

有 4 种不同的方式会发生这种情况,忽略以前版本的 Xcode 中的错误

  • You don't have a umbrella header named $(TARGET_NAME).h in your project
  • You have a umbrella header, but it's not set as public. See arturgrigor's answer
  • DEFINES_MODULEis not set to YES
  • CLANG_ENABLE_MODULESis not set to YES
  • 您的项目中没有名为 $(TARGET_NAME).h 的伞头
  • 你有一个伞头,但它没有设置为公开。参见 arturgrigor 的回答
  • DEFINES_MODULE未设置为 YES
  • CLANG_ENABLE_MODULES未设置为 YES

回答by Aleksei Minaev

For me - access level was public but it also fails on umbrella not found. I did move the "Headers" section of the "Build phases" to the top and it started to work. Script to podfile:

对我来说 - 访问级别是公开的,但在找不到伞时也会失败。我确实将“构建阶段”的“标题”部分移到了顶部,它开始工作了。podfile 脚本:

post_install do |installer|
installer.pods_project.targets.each do |target|
    phase_name = 'Headers'
    target.build_phases.each do |phase|
        if (phase.display_name.include? phase_name)
            target.build_phases.unshift(phase).uniq! unless target.build_phases.first == phase
        end
    end
end

Have no clue why it is happening. Tried on dummy projects - not happening. Only on big ones with multiple dependencies. Something with compiling BEFORE copying umbrella headers.

不知道为什么会这样。尝试过虚拟项目 - 没有发生。仅适用于具有多个依赖项的大型应用程序。在复制伞头之前编译的东西。

回答by Bart?omiej Semańczyk

Definitely you must to set your framework to public:

当然,您必须将您的框架设置为公开:

enter image description here

在此处输入图片说明

回答by Danra

One more solution: After renaming a folder, the old location might still be listed in the project file for the .h file, even if you updated the location via Xcode's side-bar. This old location causes the umbrella-header error.

另一种解决方案:重命名文件夹后,旧位置可能仍会列在 .h 文件的项目文件中,即使您通过 Xcode 的侧栏更新了该位置。这个旧位置会导致伞头错误。

Simple solution: Remove the reference to the .h file, and re-add. (and then remember to make it public again!)

简单的解决办法:去掉对.h文件的引用,重新添加。(然后记得再次公开!)

回答by xySVerma

For me setting 'Use Header Maps' to 'NO' resolved the issue

对我来说,将“使用标题映射”设置为“否”解决了这个问题

回答by Max MacLeod

There's some excellent answers here already. @Shadow_x99's was very helpful. However, if I could be allowed to supplement with my own experience.

这里已经有一些很好的答案。@Shadow_x99 非常有帮助。但是,如果可以让我补充一下我自己的经验。

An umbrella header is identified automatically in the build process. It is not a specified in the target's build settings or inherited from the project settings.

在构建过程中自动识别伞头。它不是在目标的构建设置中指定的,也不是从项目设置继承的。

So to avoid this error that - as of XCode 7- is as follows;

所以为了避免这个错误 -从 XCode 7 开始- 如下;

warning: no umbrella header found for target 'MyTarget', module map will not be generated

warning: no umbrella header found for target 'MyTarget', module map will not be generated

two important steps must be taken.

必须采取两个重要步骤。

Firstly, the umbrella header must have the same name as the target. So if your target is a framework named MyTarget, there must be a header named MyTarget.h.

首先,伞头必须与目标名称相同。因此,如果您的目标是一个名为 的框架MyTarget,则必须有一个名为MyTarget.h.

Secondly, in the build phases for MyTarget- as mentioned in that answer - that header file must be listed in the public sectionas detailed above.

其次,在构建阶段MyTarget- 如该答案中所述 - 该头文件必须列在上面详述的公共部分中。

回答by Jonathan.

I found that with the New Swift Build System and Parallelize Build turned on the scheme I would get errors like in this question. The solution was to link to frameworks that had been imported in the swift source files. (I think previously the app would build because it just happened that the frameworks were linked to something built previously in the serial build queue).

我发现随着 New Swift Build System 和 Parallelize Build 打开该方案,我会得到类似这个问题的错误。解决方案是链接到在 swift 源文件中导入的框架。(我认为以前该应用程序会构建,因为恰巧框架已链接到先前在串行构建队列中构建的某些内容)。

I wrote a script to go through all the imports in all the targets in a workspace and make sure that their frameworks have been linked to in that target.

我编写了一个脚本来检查工作区中所有目标中的所有导入,并确保它们的框架已链接到该目标中。

https://github.com/Jon889/SwiftImportChecker

https://github.com/Jon889/SwiftImportChecker