简体   繁体   中英

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

In a custom framework containing both Objective-C and Swift code, the Swift compiler throws the following error:

[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'

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

使固定

In Xcode 7 Beta, with Swift 2, it will also happen if your Framework Header is not declared as "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

There's 4 different ways this can happen, ignoring bugs in previous versions of 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_MODULE is not set to YES
  • CLANG_ENABLE_MODULES is not set to YES

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

Setting it to No will resolve that error.

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

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:

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.

Definitely you must to set your framework to public:

在此处输入图片说明

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

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.

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

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).

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

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.

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;

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 .

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

Your header file needs to be in the [Build Phases/Headers/Public] section.

If your header file is already in the [Build Phases/Headers/Public] section, many times doing the fallowing solved my problem:

  1. clean the project
  2. move the header file to the "private" or "project" section
  3. move the header file back to the "public" section
  4. rebuild everything again

I had the same issue and none of the suggested answers helped in my case so I'm leaving this here in case someone has the same problem.

I had added a "Run script" in "Build phases" but ended up removing it and that's when I started getting the error.

My solution ended up having to clean the project, rebuild my framework and then my app project built correctly.

In my experience you have to choose on the targets the framework which is giving you the error, not the project target.
Then compile, and after compiling it will be available on the project target.

If you're using Xcode 7.1 and CocoaPods 0.39, there seems to be a swift compiler change that affects some CocoaPods (Nimble, Quick, etc.) Try some of the solutions specified in the this thread: https://github.com/CocoaPods/CocoaPods/issues/4420 however, if neither of them work, try using Xcode 7.0.1 or 7.2 beta. You can get both of them here: https://developer.apple.com/downloads/ .

Edit: In my case, to fix the issue, I also had to downgrade CocoaPods to 0.38.2.

Later edit: It seems not to be related to Xcode 7.1. Just downgrading CocoaPods to 0.38.2 should help:

sudo gem uninstall cocoapods -v 0.39
sudo gem install cocoapods -v 0.38.2

我通过将我的 module.modulemap 重命名为 moduleXYZ.modulemap 并在项目设置中更改 modulemap 文件名解决了这个问题

In my case, I just built the specific framework with it's scheme. And then rebuild the entire project and it resolved the issue

确保构建设置中的“导入路径”包含您尝试包含的文件...

None of these fixes above were successful, but after much investigation into cocoapods I discovered this issue was caused by a git configuration where symbolic links were not being created in the git filesystem. These symbolic links are needed to let Xcode know where the headers are for the framework.

The fix:

git config --global core.symlinks true

and reset the file system for git git reset --hard HEAD

and then do a clean build.

In my case, the problem appears to have been with an incomplete installation of Xcode 13.3 (13E113).

Here's the error that lead me to this:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.4.sdk/System/Library/Frameworks/Accessibility.framework/Modules/module.modulemap:2:19: umbrella header 'Accessibility.h' not found

It turns out that the header file was literally missing from within the SDK (inside the Xcode app bundle). Looking in the Headers directory of that Accessibility.framework bundle.

This is what it should be:

$ ls -l
total 80
-rw-r--r--  7 andrew  staff  12307 Feb 23 06:14 AXAudiograph.h
-rw-r--r--  1 andrew  staff   2013 Feb 23 06:57 AXBrailleMap.h
-rw-r--r--  1 andrew  staff    402 Feb 23 06:57 AXColorUtilities.h
-rw-r--r--  1 andrew  staff   2612 Feb 23 06:57 AXCustomContent.h
-rw-r--r--  1 andrew  staff    395 Feb 17 01:04 AXFoundation.h
-rw-r--r--  1 andrew  staff   2109 Feb 23 06:57 AXHearingUtilities.h
-rw-r--r--  1 andrew  staff    349 Feb 17 01:04 Accessibility.h

But on this Mac, that directory is empty:

$ ls -l
total 0

We aren't yet sure how this happened. But this particular instance of Xcode is installed in CI, and the installation of Xcode is automated.

Make sure Header Search Paths (HEADER_SEARCH_PATHS) build setting points to a directory with headers you include in a module.

Remove these files from project's directory. .xcworkspace pods/ and podfile.lock

update the pod and build the project.

In my case problem was caused by remove headers script in Build Phases

function removeHeaders() {  
    find $BUILD_ROOT/...  -name '*.h' -exec rm -f {} \;  
}  
removeHeaders

Deleting this script fixed the problem.

我通过将有问题的框架构建设置的编译模式设置为增量来修复它。

None of the 9 answers helped me, so I tried to create a new project which I could send to Apple to file a bug. I was surprised that I couldn't reproduce the issue. I checked the build settings and they were equivalent. Apparently this is some kind of bug.

If nothing else helps , try to create a new project and import at least some Objective C & Swift classes from your current project, compare your framework-related build settings to the default values from the new project, and eventually move all files over to the new project.

I've been working on it for a whole day,but it's worth it.I tried all the ways here, but I didn't solve it. I created a new project, an experiment, and I found out User Header Search Path was setted ${SRCROOT} recursive , and I changed it to ${SRCROOT} non-recursive , changed the bridging header path(eg #import "SVProgressHUD.h" -> #import "Pods/SVProgressHUD/SVProgressHUD/SVProgressHUD.h" ), the error went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM