Framework header file not found error in Xcode 8 editor

Since Xcode 8 we get a file not found error in the Xcode editor when importing the umbrella header for a framework.


The framework and the project that depends on it (both Objective-C projects) build without a single error or warning, but the Xcode editor complains that the framework header can't be found. Syntax highlighting and code navigation are broken for that file. The error is only displayed when the file is being edited and briefly disappears whenever the project is built (because it builds successfully) but then reappears after a couple of seconds.


This is a project that was created in Xcode 7. We don't see this issue in that version. These errors only appear in Xcode 8 (we've tried 8.1 and 8.2).


The two projects are both framework projects. The imported framework's xcodeproj file is referenced by the dependent project (i.e. the xcodeproj file was added to the project using "Add Files to MyProject.xcodeproj..." The dependency is listed in the "Linked Frameworks and Libraries" section of the dependent project's settings and is listed in the "Target Dependencies" build phase.


This problem is driving me crazy. I've spent countless hours deleting DerivedData, re-constructing projects from scratch, cleaning, re-building but nothing helps. Xcode 8 simply refuses to index the symbols from the dependency framework.


Does anyone have an idea what is causing this error?


Many thanks,

Simon

Replies

I think I am seeing the same problem, though my setup is slightly different. I am including a .framework file in my project, and it will build and run OK, so obviously there's nothing (major) wrong. However, every time I edit the file that uses the framework, I immediately get error messages that pop up and tell me I have an framework error (not a warning). But the error messages go away as soon as I build and run (but reappear after a few seconds). I have figured out to ignore the error messages, but it is very confusing for anyone else who may come along and use the project, and think they have a real problem. It also inhibits auto-complete and makes it harder to use the framework classes and functions.


Error messages while editing say "Swift compiler error: MySharedClass is unavailable : Cannot find Swift declaration"

I don't have an answer for you, but it's worth asking what "including a .framework file" means in your case. Did you add an item to the navigator panel on the left? Did you use the Embedded Binaries and/or Linked Frameworks and Libraries lists in the General tab of the target info?


Your problem may have nothing to do with the OPs, since you're using Swift (only? also some Obj-C? is the framework Obj-C or Swift?) and the OP was using Obj-C exclusively. However, in places where your project refers to the framework (the project navigator, the lists mentioned above, build phases) you should ensure that the framework reference is build-products-relative, not project relative or absolute. Also, examine your build settings for the include and frameworks paths. Xcode sometimes puts an undesirable path there when you drag something into your project.


Since your problem is (presumably) that Source Kit and the Swift compiler are coming up with different lists of things to include at compile time, and that shouldn't really happen, it would probably be a good idea to submit your project with a bug report.

I had a run of the mill "Header not found" problem for a framework and solved it by adding a long and convoluted path to the Header Search Paths in the Build Settings. That this is necessary is a screwup, IMHO.


M.

Sorry Quincy, did not notice your reply until yesterday. It did not directly solve my problem but your suggestions led me to discover it.


So in my case, everything is Swift. Swift app using a Swift framework. The Swift framework generates the .framework file and sticks it in a special build location so our other projects can find it there. That build products path, relative to the app project, happens to be "../../Build/Products/". To get the app to build properly, I set its "framework search path" to "../../Build/Products/" and it works. Except for the problem in this thread, the editor and CodeSense keep saying there is a problem finding the framework. To fix this, I tried setting every possible path (include, library, etc.) I could, changing from project relative to build products relative to absolute, but nothing worked, until...


I changed the app's "build products path" to match the same location as the framework build products path. (To do this, one goes to File->Project Settings->Advanced->Custom). This never occurred to me, because I didn't think it would matter where those app output build products ended up, once the app found all the necessary frameworks and input sources.


I do think this is a legitimate XCode bug and I will file a bug report. If the project can find everything it needs to compile and link and build an IPA, then the code editor should be happy, too.

Has anyone solved this yet? I have Xcode 12.4 and created a trivial project (Objective-C) that links in a simple other project (for my base types). The other project has it's BaseTypes.h include the .h of the main code. This base project, KSBaseTypes, compiles nicely by itself.
Code Block
// In this header, you should import all the public headers of your framework using statements like #import <KSBaseTypes/PublicHeader.h>

But when incorporated into the workspace of the test project, both the original BaseTypes.h won't compile, and any user of those types also aren't found.

Code Block
#include <KSBaseTypes/KSFrameworkRoot.h> --error: 'KSBaseTypes/KSFrameworkRoot.h' file not found

The test main gets this error:
Code Block
#import <KSBaseTypes/KSBaseTypes.h> --error: Could not build module 'KSBaseTypes'

As this is a trivial example, what is going wrong with frameworks? I'm not going to mess with search paths unless some Apple doc says so (I tried).

Also, the error on building when combined is:
Code Block
/Users/scott/Documents/Xcode/ExampleFromWeb/KSBaseTypes/KSBaseTypes/KSBaseTypes.h:10:10: Did not find header 'KSFrameworkRoot.h' in framework 'KSBaseTypes' (loaded from '/Users/scott/Library/Developer/Xcode/DerivedData/ScottyTestTypes-bfwsyutnpcgxeuhbksuzfzelkbli/Build/Products/Debug-iphonesimulator')

So maybe the other .h files aren't pushed to this DerivedData folder? The other .h files are not in the public or private headers copy build phase (so I'm searching that issue).

SOLVED:
I had to manually add the .h files from the framework into the build phase (eg. KSFrameworkRoot.h) and it works nicely.

thanks.