failed to emit precompiled header - xcode

Good Afternoon
I am trying to implement googles heatmaps into my map based project.
In this particular project, I get the following errors when trying to build.
failed to emit precompiled header '/Users/zachwilcox/Library/Developer/Xcode/DerivedData/OddJobs-gbnkfettubuccoheinzfovrqefub/Build/Intermediates.noindex/PrecompiledHeaders/OddJobs-Bridging-Header-swift_3WGH9SNI96Z2-clang_16JN3VASQHE4C.pch' for bridging header '/Users/zachwilcox/Desktop/OddJobs/OddJobs-Bridging-Header.h'
and a follow up that says
'Google-Maps-iOS-Utils/GMUHeatmapTileLayer.h' file not found
I'm not sure why this is happening because I created an entirely new project and did the same implementation and it worked perfectly. But when I run it on my existing project I get these two errors.
I have been researching this problem for a while now and I can't figure out what the problem is. I have the Bridging header set to the .h file.
I have tried most steps that individuals have tried to give with their answers but for some reason, it's not working for my project. Thank you in advance. When reading googles installation guide, it said that all I needed to add was one bridging header file which is the code you see in the image below. When researching it, I have seen that I needed to add a .m file as well however I still get the same error when I do. again, in my dummy project, I don't have the .m file just everything you see below and everything compiles.

There are chances you have 'Find Implicit Dependencies" turned off for the selected Scheme. If you have updated/installed pods and try to build the project, it will more likely fail if this option is unchecked for the selected Scheme.
From Apple's Document:
Parallelize Build – This option allows Xcode to speed up total build time by building targets that do not depend on each other at the same time. This is a time-saver on projects with many smaller dependencies that can easily be run in parallel.
Find Implicit Dependencies – This is a very powerful option that allows Xcode to resolve what targets need to be built for the primary target of the scheme to be built successfully. However, this does come with some sharp edges that you have to be aware of.
Situation: You link a library against your application target and create an implicit dependency to that library’s target.
Scenario 1: “Find Implicit Dependencies” is enabled.
Result: The library will get built prior to building the application target. The application target will then link against the library and build successfully.
Scenario 2: “Find Implicit Dependencies” is disabled.
Result: The library will not get built prior to building the application target. The application target fail to build.
Fix: To ensure that the second scenario does not happen, you must add the necessary targets into the targets list and order them correctly.

If your project includes pod then you've to set the pod configuration for the test project too..
Select Root Project in File inspector -> Project Name -> Info -> Configurations
Set configuration for your test project same like your main project

Related

Why does exact copy of Xcode Build Configuration fail?

I have a react-native app with bridged Swift code that is building, running, and archiving without issue with Xcode 10.0 with the default Release and Debug build configurations. I use Xcode -> Product -> Archive or the "Play" button and everything works as expected. Great!
Then today I added a new build configuration that is an exact duplicate of Release. It is named Release copy. I did the same for Debug as well, and its duplicate is Debug copy.
If I try to run the same Archive or Run tasks using the copies, the tasks fail at Precompile bridging header.
/Users/whaley/dev/app/theApp/theApp-Bridging-Header.h:5:9: error: 'React/RCTBridgeModule.h' file not found
#import <React/RCTBridgeModule.h>
^
1 error generated.
<unknown>:0: error: failed to emit precompiled header '/Users/whaley/Library/Developer/Xcode/DerivedData/theApp-ckvpglaqydwzhadbbyqoprcjvnod/Build/Intermediates.noindex/ArchiveIntermediates/theApp/PrecompiledHeaders/theApp-Bridging-Header-swift_320079J7441HX-clang_QK5YQQC41WXA.pch' for bridging header '/Users/whaley/dev/theApp/ios/theApp-Bridging-Header.h'
Odd, in my opinion, since this should be an exact copy of a build configuration that was working fine.
If I switch back to the original Build Configurations everything is fine. The originals consistently work and the copies consistently fail.
I tried disabling the Precompile bridging header task, but just encountered a different, and similar error. Again, the original build configs worked where the copies failed.
I'm already using Find implicit dependencies, the bridging header is named properly, I'm not using Cocoapods, I've rebooted and cleared Xcode's Derived Data, and please bear in mind that it does work fine normally. It's only these duplicate build configurations that fail.
Why might this be happening? Am I missing a step here? Is this perhaps a limitation of react-native and it only supports the default build configs?
Naturally, the moment I posted my question I managed to find the answer I needed via Google
Thanks to Mateusz Klimczak for clearly illustrating the problem and resolution on their website.
Add an entry to Headers Search Paths for each new Release build configuration:
$(BUILD_DIR)/Release-$(PLATFORM_NAME)/include
Add an entry to Library Search Paths for each new Release build configuration:
$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
One might wonder why this is needed when we only change build configuration name and it was already working for Release. React Native supports Debug and Release build configurations out of the box, while any other configuration needs to be set up manually.
Sure enough, that fixed it. The answer is that only Release and Debug are supported out of the box, so that additional config is required for non-standard Build Configurations.

Swift build fails: target might include it's own product

Has anyone run into this issue? I was experimenting with porting an existing obj-c app to Swift, and after quite a few successful builds the project will no longer build and immediately gives the error: Unable to run command 'CompileSwift normal' - this target might include its own product. Along with many other 'target might include it's own product errors'.
What I've Tried:
Checking Target Dependencies: There is nothing listed as a target dependency in Build Phases.
I've tried completely deleting the product folders, and have went through all the files multiple times but with no luck.
If I simply replace the Swift files with the old obj-c files it builds fine, no errors at all.
Restoring to a snapshot prior to any Swift modifications results in building as normal, but even if I add a brand new Swift boilerplate file and bridging header, then click build, it fails with the same errors.
I had the same issue. I couldn't work out exactly what was causing it, but realised the same code would build find on a different Xcode 6 install on a different machine.
I solved it by deleting my cached builds, etc, in ~/Library/Developer/Xcode, while Xcode is not running. "Clean" alone from within Xcode didn't do it.
You should find that when you re-launch Xcode your app will build fine.
Deleting my app target from "Build Phases -> Copy Bundle Resources" worked for me. (Somehow it was being included for bundling?)
I could reproduce the problem. In the objc-to-swift bridge header I imported a header of an objc class, which also imports swift-to-objc header. There was a cycle of imports and this could be the reason Xcode complaint.
I think for now it is best to avoid such cyclic importing between swift and objc. You might want to check that out.

How can I get Xcode to Compile my code instead of doing Build AST?

I just converted a Framework project from Xcode 3 to Xcode 4. I've been building this project for years under every version of Xcode and Project Builder.
For some reason, Xcode 4 runs Build AST on all of my classes rather than Compile, which doesn't actually build the framework executable. On digging into it I found that this passes the -fsyntax-only flag to clang which tells it to stop after producing an Abstract Syntax Tree for each class. I have another Framework that builds fine in Xcode 4, and I've compared the build settings without uncovering anything that looks like it would cause this.
Does anyone have an idea what would make Xcode want to perform the Build AST action rather than Compile? And more to the point, how to turn that behavior off?
Thanks for any ideas...
Okay, I found that in my case I had a custom Build Rule for '*.i' files in my project. The clang build process apparently produces .i files (along with several others) as an intermediate product, so this rule was interfering and stopping it from completing all stages of the build. Removing the custom Build Rule allowed everything to build normally.

Adding OCHamcrest to an IOS Project

The documentation for the project says just add the framework and the linker flags and you are good to go. Hours and hours of wasted time later, I have figured out that that's not true. If you do that, the project does not see the header files. You have to put the framework somewhere were the compiler will find the headers. In my case, that worked when I dropped the framework into /Developer/Library/Frameworks and then told it to recurse in searching that framework directory (do not fiddle around with the headers search directories).
Then the problem I get is that the link fails with the message:
ld: framework not found OCHamcrestIOS
I noticed that the documentation for the project says that it was updated for Xcode 4. I pulled down the binary of the framework after checking out the code and wasting a ton of time unable to build the IOS version of the framework.
The documentation is here.
I also noticed in that documentation that the cocoa instructions tell you to put a copy files phase into the build. I tried that. Didn't change the outcome.
The last time I fell into a sink hole it was because the library was C++ code. Maybe that's still the problem.
Barring a rapid solution here, I am going to go back to using STAsserts, as sickening as that prospect is, this is far, far worse.
Update: reinstalled Xcode. Still doesn't work. There are cheap ways to make this work, like add the header files to the project. Did a blog post about this that brought out a person with the same experience.
I use a number of frameworks in my projects. Some from other people and some are mine. Looking at the documentation I would suggest that the copy phase stuff is not for iOS development. So I would not do that. I downloaded the latest zip from https://github.com/jonreid/OCHamcrest and it appears to contain a ready to go iOS static library. (Not on my mac so I cannot test to confirm).
Anyway, the way I include static libs is to
Select the project (XCode 4).
Select the target I want to add the library to.
Select the Build phases tab.
Expand Link binary with Libraries.
Click the [+] button to add a framework.
Click the [Add Other ...] button and navigate to the directory containing the <lib>.framework directory and select that.
Thats all. The targets search paths will be updated to include the framework directory and the framework will be listed on the left under the project. Expanding it will show the headers.
The problem you mention sound like a couple of things. Firstly the framework not found sounds like the framework has not been included in the target. When you select the framework in the project list on the left, you should be able to see it's Target Membership displayed on the right. Check it's on for the target you are compiling.
Secondly building frameworks is not a trivial task so don't attempt it unless you have the scripts to do it. I say this because building a iOS static framework means compiling for both simulator and devices, combining the compiled lib files into a universal one, and then storing it and the header in a specific directory strucuture.
The downloaded zip from OCHamcrest though, appears to have the correct OCHamcrestiOS.framework in it. So if you store that directory somewhere and link to it using the steps I've outlined above it should work just fine.
So the solution I adopted for now, after much thrashing around, was to include the framework in the project.
Create a group inside the Xcode project called Third Party.
Link it to a folder called thirdparty.
Go to the Add Files in Xcode and pick the framework.
Drag it over to the dependencies.
Run the tests, they pass!
This is maybe preferable anyway because referencing it in /System/Library/Frameworks would present some versioning issues, and this can be setup very quickly. Furthermore, we have a continuous integration server, and having to get in there and sync versions whenever something changes is not so great.
Thanks for checking it out, Derek.

Adding a framework in Xcode

Im trying to add a third party framework in Xcode but I'm getting an error that it can't be found
error: MKAbeFook/MKAbeFook.h: No Such File or Directory
I've added it in the Linked Frameworks group and added it to the Target for this project. I've also added it to a new Copy Files build phase for that target.
Basically I've followed the instructions here: http://pointlesscrap.net/mkabefook/desktop/gettingstarted
Any ideas where I'm going wrong?
Best way to diagnose this is to post the compiler invocation line, not just the error (you can just drag and drop the line from the Build Results window that says "Compiling foo.m"). My expectation is that you don't have a Frameworks Search Path set up for the location of the framework. Xcode usually adds that manually when you add the framework, but if you put it in certain kinds of places, or added it in certain ways, you need to manually point your target's Framework Search Paths at its directory.
Perhaps the author mistook MKFaceBook for MKAbeFook?
EDIT: Never mind, it looks like that is actully the name of the framework.

Resources