iOS - 构建失败,CocoaPods 找不到头文件

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

iOS - Build fails with CocoaPods cannot find header files

objective-cioscocoabuildcocoapods

提问by Filip Majernik

I have an iOS project using CocoaPods. Everything was working smoothly until another developer started to work on the same project. He made some changes (only to code as far as I know) and made a new branch in the repo. I have checked out his branch and tried to build it, but I am getting an error: ASLogger/ASLogger.h file not found.

我有一个使用 CocoaPods 的 iOS 项目。一切都很顺利,直到另一个开发人员开始从事同一个项目。他进行了一些更改(据我所知仅对代码进行了更改)并在 repo 中创建了一个新分支。我检查了他的分支并尝试构建它,但我收到一个错误:ASLogger/ASLogger.h 文件未找到。

Even if I delete the whole project and make a fresh copy and use 'pods install .' the build failure is still there. Do you have any idea where the problem can be? If you need some more infos, just ask.

即使我删除整个项目并制作一个新副本并使用“ pods install ”。构建失败仍然存在。你知道问题出在哪里吗?如果您需要更多信息,请询问。

回答by waggles

Update

更新

Make sure your Podfileincludes link_withon targets missing a config file. Cocoapods only sets the first target by defaultotherwise. e.g.

确保您Podfile包含link_with的目标缺少配置文件。否则 Cocoapods默认设置第一个目标。例如

platform :osx, '10.7'
pod 'JSONKit',       '~> 1.4'

link_with 'Pomo', 'Pomo Dev', 'Pomo Tests'

------ End Update

------ 结束更新



Note: Please do note that you have to look into Project->Info->Configurations for steps below.

注意:请注意,您必须查看 Project->Info->Configurations 以了解以下步骤。



I had similar symptoms and found that the pods.xcconfigfile was not being included in the specific targetI was trying to build. Some of the other suggested solutions worked for me, but this one seemed to address part of the underlying issue.

我有类似的症状,发现该pods.xcconfig文件未包含在target我尝试构建的特定文件中。其他一些建议的解决方案对我有用,但这个解决方案似乎解决了部分潜在问题。

Pods.xcconfig not working

Pods.xcconfig 不工作

The simple solution was to change set the configuration file for the targets that didn't have one set.

简单的解决方案是为没有设置的目标更改设置配置文件。

Pods.xcconfig working

Pods.xcconfig 工作

回答by Bill Burgess

Update

更新

I've updated this since my original answer, that got the downvote, so I hope this helps. And if it does, hopefully it will get my vote back.

自从我最初的回答得到了反对票后,我已经更新了这个,所以我希望这会有所帮助。如果是这样,希望它能让我重新投票。

If the headers aren't being imported, you probably have a conflict in the HEADER_SEARCH_PATHS. Try and add $(inherited)to the header search paths in your Build Settings to make sure that it pulls in any search paths included in the .xcconfig file from your CocoaPods.

如果未导入标头,则HEADER_SEARCH_PATHS. 尝试添加$(inherited)到您的构建设置中的标题搜索路径,以确保它从您的 CocoaPods 中提取包含在 .xcconfig 文件中的任何搜索路径。

This should help with any conflicts and get your source imported correctly.

这应该有助于解决任何冲突并正确导入您的源。

回答by Albert.Qing

1.Check

1.检查

build settings -> Search Path -> User Header Search Paths ->

构建设置 -> 搜索路径 -> 用户标题搜索路径 ->

  • "${PODS_ROOT}/" recursive
  • "${PODS_ROOT}/" 递归

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

2.Check import style(KEY POINT), if your's podfilehave set

2.检查导入样式(KEY POINT),如果你的podfile已经设置

use_frameworks!

use_frameworks!

In yours File-Bridging-Header.h,the formatter should like this

在你的File-Bridging-Header.h,格式化程序应该是这样的

#import "MBProgressHUD.h"

#import "MBProgressHUD.h"

else should be below

否则应该在下面

#import <MBProgressHUD.h>

#import <MBProgressHUD.h>

3.That must be work! trust me

3.那一定是工作!相信我

回答by averydev

Header files, you'll be the death of me...

头文件,你会是我的死...

Finally got it to work by adding (including quotes)

最后通过添加(包括引号)使其工作

"${PODS_ROOT}/BuildHeaders"

to the User Header Search Paths entry, and checking 'recursive'.

到用户标题搜索路径条目,并检查“递归”。

回答by mactive

I found ${PODS_HEADERS_SEARCH_PATHS}is missing and it is not defined in my develop git branch, So I added "$(SRCROOT)/Pods/Headers/"for Header Search Paths with recursive

我发现${PODS_HEADERS_SEARCH_PATHS}缺少并且它没有在我的开发 git 分支中定义,所以我添加 "$(SRCROOT)/Pods/Headers/"了带有递归的标题搜索路径

That is ok for me

这对我来说没问题

回答by brainray

Both other answers didn't help here. I found 2 other problems that might fix it:

其他两个答案在这里都没有帮助。我发现了其他 2 个可以解决它的问题:

EDITYou can check a symlink this way: create a textfile named 'check' without an extension. copy these lines into it:

编辑您可以通过这种方式检查符号链接:创建一个没有扩展名的名为“check”的文本文件。将这些行复制到其中:

file=/Users/youUserName/XcodeProjectName/Pods/BuildHeaders/SVProgressHUD/SVProgressHUD.h
if [[ ! -e $file &&  -L $file ]]; then
  echo "$file symlink is  broken!"
else
  echo "symlink works"
fi

Then go to the terminal, change to the folder where your check file is located and type

然后转到终端,切换到检查文件所在的文件夹并键入

bash check

回答by Snowcrash

Here's what worked for me:

以下是对我有用的内容:

Go to the Target > "Build Settings" tab and find the "User Header Search Paths" setting.

转到“目标”>“构建设置”选项卡并找到“用户标题搜索路径”设置。

Set this to "$(BUILT_PRODUCTS_DIR)" and check the "Recursive" check box.

将其设置为“$(BUILT_PRODUCTS_DIR)”并选中“Recursive”复选框。

Now the built target will search the workspace's shared build directory to locate the linkable header files.

现在构建的目标将搜索工作区的共享构建目录以定位可链接的头文件。

====

====

UPDATE

更新

I had a similar (although slightly different) problem recently. It turned out Xcode couldn't find the Pods because I had opened up the .xcodeprojfile rather than the .xcworkspacefile. Might help others in the future.

我最近遇到了类似(虽然略有不同)的问题。结果 Xcode 找不到 Pod,因为我打开的是.xcodeproj文件而不是.xcworkspace文件。将来可能会帮助别人。

回答by Scott Fister

If none of the above worked for you and you are finding this error because you just switched to use_frameworks!in your Podfile, read on:

如果以上都不适合您,并且您发现此错误是因为您刚刚use_frameworks!在 Podfile 中切换到,请继续阅读:

I tried all the solutions above and a lot more before learning that it isn't about search header paths at all in my particular case; it's that when you switch to use_frameworks!in your Podfile you no longer need to include frameworks in your bridging header, and in fact Xcode will throw the very unhelpful "unable to find header" error.

在了解到在我的特定情况下根本与搜索标题路径无关之前,我尝试了上述所有解决方案以及更多解决方案;这是因为当您切换到use_frameworks!Podfile 时,您不再需要在桥接头中包含框架,实际上 Xcode 会抛出非常无用的“无法找到标题”错误。

What you need to do is remove all imports from your bridging header file, and instead use the Swift import Modulein your individual Swift files as needed, just like you would for Swift frameworks.

您需要做的是从桥接头文件中删除所有导入,而是import Module根据需要在您的各个 Swift 文件中使用 Swift ,就像您使用 Swift 框架一样。

AND if you are using any of the framework headers in your Obj-C classes (in my case we have a convenience class that used the FBSDK) you need to change it from a local to global import (this means change #import "Module.h"to #import <Module/Module.h>, which should autocomplete for you when you begin to type the framework name. In my case it was <AFNetworking/AFHTTPRequestOperationManager.h>).

并且如果您在 Obj-C 类中使用任何框架头文件(在我的情况下,我们有一个使用 FBSDK 的便利类),您需要将其从本地导入更改#import "Module.h"为全局导入(这意味着更改为#import <Module/Module.h>,这应该自动完成当您开始输入框架名称时,为您提供。在我的情况下,它是<AFNetworking/AFHTTPRequestOperationManager.h>)。

Edit: I've since learned that doing an @import Moduleuses the umbrella file which is even safer.

编辑:从那以后,我了解到做一个@import Module使用更安全的伞文件。

回答by Tieme

Did you try importing Cocoapods style?

您是否尝试导入 Cocoapods 样式?

#import <ASLogger.h>

The info on the site is not really clear, I submitted a pull request:

网站上的信息不是很清楚,我提交了一个拉取请求:

https://github.com/CocoaPods/cocoapods.org/pull/34

https://github.com/CocoaPods/cocoapods.org/pull/34

Update:They pulled my request :)

更新:他们取消了我的请求:)

回答by tilo

The wikigives an advice on how to solve this problem:

维基对如何解决这一问题的建议:

If Xcode can't find the headers of the dependencies:

Check if the pod header files are correctly symlinked in Pods/Headers and you are not overriding the HEADER_SEARCH_PATHS (see #1). If Xcode still can't find them, as a last resort you can prepend your imports, e.g. #import "Pods/SSZipArchive.h".

如果 Xcode 找不到依赖项的标头:

检查 Pod 头文件是否在 Pods/Headers 中正确符号链接,并且您没有覆盖 HEADER_SEARCH_PATHS(参见 #1)。如果 Xcode 仍然找不到它们,作为最后的手段,您可以在导入之前添加,例如 #import "Pods/SSZipArchive.h"。