iOS - Build fails with CocoaPods cannot find header files

Objective CIosCocoaBuildCocoapods

Objective C Problem Overview


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.

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.

Objective C Solutions


Solution 1 - Objective C

Update

Make sure your Podfile includes link_with on targets missing a config file. Cocoapods only sets the first target by default otherwise. e.g.

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.


I had similar symptoms and found that the pods.xcconfig file was not being included in the specific target I 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 not working

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

Pods.xcconfig working

Solution 2 - Objective C

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.

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

Solution 3 - Objective C

1.Check

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

  • "${PODS_ROOT}/" recursive

enter image description here

enter image description here

enter image description here enter image description here

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

use_frameworks!

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

#import "MBProgressHUD.h"

else should be below

#import <MBProgressHUD.h>

3.That must be work! trust me

Solution 4 - Objective C

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

Solution 5 - Objective C

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

That is ok for me

Solution 6 - Objective C

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

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

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

Solution 7 - Objective C

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.

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 .xcodeproj file rather than the .xcworkspace file. Might help others in the future.

Solution 8 - Objective C

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:

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.

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

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

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

Solution 9 - Objective C

Did you try importing Cocoapods style?

#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

Update: They pulled my request :)

Solution 10 - Objective C

The wiki gives 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".

Solution 11 - Objective C

I was the only developer in the team experiencing this same issue, it worked perfectly for everybody so I realized it had to be my environment. I tried a git clone of the same project in another directory and it compiled perfectly, then I realized it had to be Xcode caching stuff for my project path somewhere, that "somewhere" is the DerivedData folder, just remove it and do a clean build of your project, it worked for me.

You can get the path and even open the folder in finder by going to:

Xcode -> Preferences -> **Locations -> DerivedData

Solution 12 - Objective C

I will update the below things in my Build settings and I did not get any errors. To check these are the things while updating your cocoapods.

Build Settings

> Enable Bit code - YES(if you are using bitcode) > > Macro preprocessor - $(inherited) > > > Other linker flag - objc, -lc++, $(inherited)

Build architecture only

> Debug - Yes > > Relese - No >

Search Path

> Framework search path - $(inherited) $(PROJECT_DIR) > > Library search path - $(inherited) > > Header search path - $(inherited)

Solution 13 - Objective C

For me, what fixed it was the iOS deployment target for my Pods project was lower than my project itself. Once I made it the same as my project it was able to find the header file.

Solution 14 - Objective C

If you had the building errors after a "pod install" or a "pod update", it may be that one of your pods have been built with XCode 6.3 while you are still using a previous version.

In my case I had to update my OSX from mavericks to Yosemite to have Xcode 6.3 and solve the problem

Solution 15 - Objective C

for me the problem was in Other Linker flags value. For some reason I had no quotes in flags like -l"xml2" -l"Pods-MBProgressHUD".

Solution 16 - Objective C

I had to download the zip from git hub and drag the missing files into the Finder at corresponding paths in Pod/...

Solution 17 - Objective C

What worked for me was selecting the Pods project, finding and selecting the target framework with the missing header in the Pod project's target directory and setting "Build Active Architecture Only" to "No" under "Architectures" in the target's build settings.

Solution 18 - Objective C

I have got the same problem, but the above solutions can't work. I have fixed it by doing this:

  1. Remove the whole project
  2. Run git clone the project and run the bundle exec pod install
  3. cd the peoject and run remote add upstream your-remote-rep-add
  4. git fetch upstream
  5. git checkout master
  6. git merge upstream/master

And then it works.

Solution 19 - Objective C

I was on the GM seed of Xcode 5.0 and I couldn't get any of these answers to work. I tried every single answer on SO on multiple different questions about header imports w/ cocoapods.

FINALLY I found a solution that worked for me: I upgraded to Xcode 5.0 via the Mac AppStore (installed on top of the GM seed) and now the header imports are working as expected.

I also still had a beta version of Xcode 5 on my system and I deleted that as well. Maybe it was a combination of the two things, but hopefully this helps someone else.

Solution 20 - Objective C

This was the answer for me, I updated cocoapods and I think that made the PODS_HEADERS_SEARCH_PATHS go away. My solution was similar to this but I used "$(PODS_ROOT)/Headers" – Andrew Aitken

Thank you so much for this answer. I had a hard time looking for ways to fix my problem. Thank you very much.

Solution 21 - Objective C

None of the answers helped me (I had my pods linked with all targets, build configurations setup properly, correclty set search paths "$(inherited)", etc...).

Problem disappeared by itself after I updated cocoapods to the newest, debug version using standard install / update command:

   gem install cocoapods --pre

or:

   sudo gem install cocoapods --pre

(if sudo was used during installation).

It must have been cocoapods bug.

Solution 22 - Objective C

One simple workaround is:

  1. Delete Pods folder and Podfile.lock file. But don't delete Podfile

  2. Run following command in your project root folder:

    pod install

Solution 23 - Objective C

Here's another reason: All the header paths seemed fine, but we still had an error in the precompiled (.pch) file trying to read a pod header

(i.e. #import <CocoaLumberjack/CocoaLumberjack.h>).

Looking at the raw build output, I finally noticed that the error was breaking our Watch OS Extension Target, not the main target we were building, because we were also importing the .pch precompiled header file into the Watch OS targets, and it was failing there. Make sure your accompanying Watch OS target settings don't try to import the .pch file (especially if you set that import from the master target setting, like I did!)

Solution 24 - Objective C

I've found that including the library as a pod install directly helps dynamic libraries. For example, for Firebase:

pod 'RNFirebase', :path => 'path/to/node_modules/react-native-firebase/ios'

Or for ASLogger:

pod 'ASLogger', :path => 'path/to/node_modules/aslogger/ios' // path to header files

Changing or hardcoding HEADER_SEARCH_PATHS did not help me. If the error ever recurs, it's not necessary to rm -rf node_modules nor delete the pod file etc, I found it useful to clear the cache.

For react-native, I run

	rm -rf $TMPDIR/react-native-packager-cache-*
	rm -rf $TMPDIR/metro-bundler-cache-*
	rm -rf $TMPDIR/metro-* 
	rm -rf $TMPDIR/react-* 
	rm -rf $TMPDIR/haste-*
	rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
	npm start -- --reset-cache

For Xcode I remove folders in ~/Library/Developer/Xcode/DerivedData

Solution 25 - Objective C

I think an ultimate solution is to go to Build settings -> Search Path -> User Header Search Paths, find your library path and go through it in a Finder. Make sure that all path exists including your import path.

For me my path was shorter than in a tutorial. In tutorial it was something like #import <SDK/path/to/sdk/File.h>, but turns out it is just #import <SDK/File.h>

Solution 26 - Objective C

If you're on Xcode 12 or above, make sure your Pods are being compiled for the correct architecture (Intel vs. ARM). Check to see if you have a VALID_ARCHS or EXCLUDED_ARCHS setting anywhere.

I had config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' in my Podfile, and that prevented the compiler from finding the Pod header files.

Solution 27 - Objective C

Have a try to comment this line for your target

#  use_frameworks!

Or you can refer to my another answer https://stackoverflow.com/questions/28343493/added-unit-testing-target-to-xcode-failed-to-import-bridging-header-wont-go-a/38630679#38630679

Solution 28 - Objective C

I solved this issues for Xcode 8.2.1 by drag and drop framework that i want to use.

Solution 29 - Objective C

I have other worked solution here,

  1. Quit Xcode
  2. Open Xcode and clean project
  3. Build Pods project first
  4. Build Project

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFilip MajernikView Question on Stackoverflow
Solution 1 - Objective CwagglesView Answer on Stackoverflow
Solution 2 - Objective CBill BurgessView Answer on Stackoverflow
Solution 3 - Objective CAlbert.QingView Answer on Stackoverflow
Solution 4 - Objective CaverydevView Answer on Stackoverflow
Solution 5 - Objective CmactiveView Answer on Stackoverflow
Solution 6 - Objective CbrainrayView Answer on Stackoverflow
Solution 7 - Objective CSnowcrashView Answer on Stackoverflow
Solution 8 - Objective CScott FisterView Answer on Stackoverflow
Solution 9 - Objective CTiemeView Answer on Stackoverflow
Solution 10 - Objective CtiloView Answer on Stackoverflow
Solution 11 - Objective CbithavocView Answer on Stackoverflow
Solution 12 - Objective CSurezzView Answer on Stackoverflow
Solution 13 - Objective CJoshView Answer on Stackoverflow
Solution 14 - Objective COmatyView Answer on Stackoverflow
Solution 15 - Objective CberylliumView Answer on Stackoverflow
Solution 16 - Objective Cneelamc23View Answer on Stackoverflow
Solution 17 - Objective CAaronView Answer on Stackoverflow
Solution 18 - Objective CAzure YuView Answer on Stackoverflow
Solution 19 - Objective CDiscDevView Answer on Stackoverflow
Solution 20 - Objective Cuser1494912View Answer on Stackoverflow
Solution 21 - Objective CLukaszView Answer on Stackoverflow
Solution 22 - Objective Cfarhad rubelView Answer on Stackoverflow
Solution 23 - Objective COwen HartnettView Answer on Stackoverflow
Solution 24 - Objective CehacinomView Answer on Stackoverflow
Solution 25 - Objective CSimon MoshenkoView Answer on Stackoverflow
Solution 26 - Objective CJoshView Answer on Stackoverflow
Solution 27 - Objective CVictor ChoyView Answer on Stackoverflow
Solution 28 - Objective CDhruv Narayan SinghView Answer on Stackoverflow
Solution 29 - Objective CPramod MoreView Answer on Stackoverflow