Search code examples
xcodecocoapodsios9xcode7google-analytics-sdk

'Google/Analytics.h' file not found - XCode 7


I am having much trouble integrating Google Analytics SDK into my iOS project. I am using XCode 7 and targeting iOS 7. Using Swift 2.0. However I can get the sample working ok (not converting to Swift 2.0 though).

I've tried both install via CocoaPods and by copying the files manually from:

https://developers.google.com/analytics/devguides/collection/ios/v3/sdk-download

When installing via CocoaPods I've tried both

pod 'Google/Analytics'

,

pod 'GoogleAnalytics'

and

pod 'Google/Analytics', '~> 1.0.0'

Either case the XCode build fails with error

BridgingHeader.h:2:9: 'Google/Analytics.h' file not found

Failed to import bridging header '/Users/jonas.andersson/Projects/MyAppName/MyAppName/Supporting files/BridgingHeader.h'

This on row:

#import <Google/Analytics.h>

I've also tried to add

$(SRCROOT)/Pods/GoogleAnalytics

and the rest of the suggestions from Google/Analytics.h file not found when adding to AppDelegate

Update

Using pod 'GoogleAnalytics' and then #import <Google/Analytics.h> worked better. However then I get the following error:

Use of unresolved identifier 'GGLContext'

when I try setup GA from according to Google documentation:

var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)

Solution

  • Solved it by going away from Googles own tutorial and not use GGLContext and importing headers directly.

    My podfile:

    platform :ios, ’7.0’
    use_frameworks!
    
    pod 'GoogleAnalytics'
    

    And BridgingHeader.h:

    #import "GAI.h"
    #import "GAIDictionaryBuilder.h"
    #import "GAIFields.h"
    

    And setup:

    let gai = GAI.sharedInstance()
    let id = "my-GA-id"
    gai.trackerWithTrackingId(id)
    gai.trackUncaughtExceptions = true 
    gai.logger.logLevel = GAILogLevel.Verbose
    

    Also added to User Header Search Paths:

    $(SRCROOT)/Pods/GoogleAnalytics (recursive)