Failed to emit precompiled header for bridging header

IosSwiftCompiler ErrorsObjective C-Swift-Bridge

Ios Problem Overview


I downloaded a project from GitHub, then pod the following files, some of which are written by OBJ-C and I used a bridge header.

pod ‘SnapKit’
pod ‘MJRefresh’
pod ‘Alamofire’
pod ‘Kingfisher’
pod ‘MBProgressHUD’
pod ‘pop’
pod ‘EVReflection’
pod ‘StreamingKit’
pod ‘iCarousel’
pod ‘ReflectionView’

When I run the project with Xcode 9.0 beta 2, but unfortunately the error log as follows :

> error: failed to emit precompiled header > '/var/folders/kd/4gh0_kxx3jx4thjb_sssmmcw0000gn/T/EvoRadio-Bridging-Header-97bd5f.pch' > for bridging header > '/Users/ringo/Downloads/EvoRadio-master/EvoRadio/Resources/EvoRadio-Bridging-Header.h'

I have googled, but no such issue.The error means it needs a PCH file? This is my .pch header configuration: enter image description here It can't solve it.

How to make it?

Ios Solutions


Solution 1 - Ios

I have tried all of the above steps mentioned in the answers but nothing worked for me, the problem was basically with the deployment target version for the project and in the podfile.

In my project deployment target was 10.0 while in my podfile it was 11.0.

Scr1

scr2

Solution 2 - Ios

Note this can also happen if your bridging header imports Objective-C code that itself imports your app's Swift module via myproject-Swift.h. The solution is to use forward declarations for your Swift types and import the project Swift module in the .m file.

@class MySwiftClass or...

typedef NS_ENUM(NSInteger, MySwiftEnumType)

MySwiftEnumType is the lowest level name even for classes. So Swift enum MyClass.MySwiftEnumType becomes just MySwiftEnumType

Solution 3 - Ios

Make sure you're opening the proper project workspace, otherwise, the Podfile may not have all the resources it needs to compile.

I saw this same error on a project that had been working fine previously.

I discovered that I had accidentally opened the ProjectName.xcodeproj file rather than the ProjectName.xcworkspace file. Opened the xcworkspace file and presto, project was working again!

Solution 4 - Ios

I also got exact same issue (Xcode9 beta 6) after I added cocoa pods for Encrypted Core Data.
This is my PodFile:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
pod 'EncryptedCoreData', :git => 'https://github.com/project-imas/encrypted-core-data.git'

target 'Root' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Root

  target 'RootTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'RootUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Solution:
1 I added $(inherited) non-recursive to Search Path -> Header Search Paths
2 Then added ${PODS_ROOT} recursive to Search Path -> User Header Search Paths
Both the above in my projects' target build settings.

Please have a look at these SO answers:
1 Inherit Header Search Paths
2 Inherit User Search Paths

Solution 5 - Ios

For me, this problem occurred when I added new build configuration and scheme to the existing project.

The solution was to run pod install on newly created scheme. After that, project was built successfully.

Solution 6 - Ios

I had this issue just when compiling for a simulator not for a hardware device. There were two compile error like:

  • error: failed to emit precompiled header 'Bridging-Header-97bd5f.pch' for bridging header 'Bridging-Header.h'
  • Could not find ActionSheetPicker_3_0/ActionSheetPicker.h in Bridging Header (but it was declared there)

After hours of research and try and errors it turned out, that there was no valid architecture set in the project to compile for simulators.

At Project -> Build Settings -> User-Defined -> VALID_ARCHS add the architecture x86_64 to enable compilation for simulators.

Solution 7 - Ios

You can try this solution. I have solved the same problem by this way.

Product > Scheme > Edit Scheme > Select "Build" on Left Menu > Find implicit dependencies

Under the build tab, check 'Find implicit dependencies':

Find implicit dependencies

Then make a clean and build again.

Solution 8 - Ios

XCode can build seccessful in the some target, but the other target can not.
Finally, I found that Header Search Paths is not the same. (Path: Target > Build Settings > Search Paths > Header Search Paths > add item)
I copied & pasted the path from the successful target. I made it. Bravo.

enter image description here

Solution 9 - Ios

In my case I had the same compiler error with additional errors like "Unknown type" in one of my project files, So I just added this to the problematic file, and it solved it instantly.

#import <UIKit/UIKit.h>

Solution 10 - Ios

In my case;

Under Target/Build Settings/

Product_Name section was different than $(TARGET_NAME)

When I changed it $(TARGET_NAME), it was resolved.

Solution 11 - Ios

My experience with this is that Xcode is unable to find header files for pods/frameworks imported in the project.

My Project experience with this: Updating Xcode9.2 - 9.3 where many cocoapods had to be updated due to implicit definitions now unavailable or being outdated.
I had changed the Podfile to now include 'use_frameworks!'. Following this and after dealing with other compile issues I found the error you are experiencing. I believe adding 'use_frameworks! was preventing some pods with support prior to iOS 8 from compiling correctly. Steps I took to correct this issue:

  1. I tried deleting the Pods/ directory using cocoa pod deintegrate

  2. I then open project with Xcode and cleaned the build folder and the project. (delete content within derived data folder)

  3. I then pod install again but the issue persisted.

  4. Ultimately I removed the use_frameworks line in Podfile and then repeated steps 1-3 and the project was now able to find the missing header files and the issue never presented it self again.

Solution 12 - Ios

For my case I had a typo in folder name "Supporing FIles" instead of "Supporting Files".

Solution 13 - Ios

Deleting Podfile.lock and re-running pod install fixed this for me.

Solution 14 - Ios

There are so many reasons and things can do, like:

The only one works for me is the accepted answer in https://stackoverflow.com/questions/46293028/xcode-9-failed-to-emit-precompiled-header.

platform :ios, '11.0' in podfile should match the target in the project

Solution 15 - Ios

I also suffered from this after I updated new Xcode. After several hours of investigation, i found that if you have multiple targets, you now have to add more targets in pod file in Xcode 10. So your code should be like this:

platform :ios, '9.0'

target 'EvoRadio' do

pod ‘SnapKit’
pod ‘MJRefresh’
pod ‘Alamofire’
pod ‘Kingfisher’
pod ‘MBProgressHUD’
pod ‘pop’
pod ‘EVReflection’
pod ‘StreamingKit’
pod ‘iCarousel’
pod ‘ReflectionView’

target 'EvoRadio2ndtarget'   # add your second target

end

I found that in Xcode 9 you don't need to add, but in Xcode 10 you need to add this. Hope this helps.

Solution 16 - Ios

In my case, I found that it was because I did not config the Framework Search Paths in Release Tab. Here is the screenshot: enter image description here

After adding this path, it works.

Solution 17 - Ios

I had same scenario, make sure for the file A that you have included in YourProjectName-Bridging-Header.h

  • if it uses some other class(s), then those other classes are also included before that File A

Solution 18 - Ios

In my case, I was building with the wrong scheme (Top-Left menu).

Solution 19 - Ios

For Xcode 11 I had an issue with the "Security.framework". I removed this dependency, then re added it. Ultimately fixed the other problems

Solution 20 - Ios

I got this error after renaming the existing Xcode project configuration in which I had another Xcode project imported.

To fix it, you have to rename the same configuration in the imported project as well.

Solution 21 - Ios

Since I have been stuck in this issue for 2 working days , I would like to share my issue for you because may be future searchers are facing my problem

I was getting the mentioned error when running with command line , and I found that the command I was writing was for running .xcodeproj ,, but to run a .xcworkspace you have to write the following command

> xcodebuild -workspace PROJECTNAME.xcworkspace clean archive > -archivePath build/PROJECTNAME -scheme SCHEMENAME

Solution 22 - Ios

In my case, all was good. I had just forgotten to add '.h' in import added to the bridging header file

Was

import 'Test'

Required

import 'Test.h'

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
QuestionRingoView Question on Stackoverflow
Solution 1 - IosParas GuptaView Answer on Stackoverflow
Solution 2 - IosHari HonorView Answer on Stackoverflow
Solution 3 - IosBAPView Answer on Stackoverflow
Solution 4 - IosD4ttatrayaView Answer on Stackoverflow
Solution 5 - IosAliensView Answer on Stackoverflow
Solution 6 - IosMarcel HofgesangView Answer on Stackoverflow
Solution 7 - IosOkanView Answer on Stackoverflow
Solution 8 - IosZgpeaceView Answer on Stackoverflow
Solution 9 - IosBenzi HelerView Answer on Stackoverflow
Solution 10 - IosVarol AKSOYView Answer on Stackoverflow
Solution 11 - IosRandorammaView Answer on Stackoverflow
Solution 12 - IosGenkiView Answer on Stackoverflow
Solution 13 - IosZack ShapiroView Answer on Stackoverflow
Solution 14 - IosAllenView Answer on Stackoverflow
Solution 15 - IosRichterView Answer on Stackoverflow
Solution 16 - IosAzure YuView Answer on Stackoverflow
Solution 17 - IosMuhammad WaqasView Answer on Stackoverflow
Solution 18 - IosatulkhatriView Answer on Stackoverflow
Solution 19 - IosMobileMonView Answer on Stackoverflow
Solution 20 - IosViktor MalyiView Answer on Stackoverflow
Solution 21 - Iosel3ankabootView Answer on Stackoverflow
Solution 22 - IosAmitView Answer on Stackoverflow