Search code examples
iosobjective-cxcodegoogle-fabric

Fabric Multiple Targets Error: Crashlytics "fatal error: 'Crashlytics/Crashlytics.h' file not found"


I am using Fabric and I had no issues before, until I added a new Target, which is required for a "Today Extension".

"Multiple Targets" of type "Today Extension"

I have added a "Run" script build phase to this newly created target with the same parameters as the "Main Target", as well as the the Fabric keys in the Info.plist for both targets.

Run Script: "${PODS_ROOT}/Fabric/run" hex_value.... hex_value...

When I build the project I am getting build errors that states:

fatal error: 'Crashlytics/Crashlytics.h' file not found

My import statement is this, and is in a file that is shared and selected to be for both targets (Target membership).

#import <Crashlytics/Crashlytics.h>

Solution

  • The Fabric run script is part of the build script and should be added to each target and should be the last item in the build phases list.

    e.g. Add the run script to the "Today Extension" target.

    (note: it is not needed to add the Fabric details to the plist file for the "Today Extension" target).

    The header file that is not found is related to the "Search Paths", and if the Fabric is installed via CocoaPods.

    Make sure the Podfile installs it for both targets.

    Run a "pod install" command after editing the Podfile. Note: the two targets both include Fabric.

    e.g.

       platform :ios, '9.0'
      # Uncomment this line if you're using Swift
      # use_frameworks!
    
      use_frameworks!
    
      target 'MyApp' do
      pod 'Fabric'
      pod 'Crashlytics', '~>  3.9'
      end
    
      target 'MoTodayExtenstion' do
      pod 'Fabric'
      pod 'Crashlytics', '~>  3.9'
      end
    
      post_install do |installer|
      puts("Update debug pod settings to speed up build time")
      Dir.glob(File.join("Pods", "**", "Pods*{debug,Private}.xcconfig")).each do |file|
      File.open(file, 'a') { |f| f.puts "\nDEBUG_INFORMATION_FORMAT = dwarf" }
      end
    

    Note the post_install part in the Podfile, this step updates/creates the xcconfig file that resides in the Xcode. Look in the "Pods" folder within the Xcode application Project;

    Inside these files are a couple of variables

    FRAMEWORK_SEARCH_PATHS 
    GCC_PREPROCESSOR_DEFINITIONS 
    HEADER_SEARCH_PATHS   
    LD_RUNPATH_SEARCH_PATHS 
    OTHER_CFLAGS 
    OTHER_LDFLAGS 
    PODS_BUILD_DIR
    etc....
    

    Specifically the "HEADER_SEARCH_PATHS" should include the path the header file that could not be found.