18

Using cocoa pods 0.37.0 in a Swift project, with use_frameworks! set in the podfile, I am unable to access the header files for the GoogleAnalytics-iOS-SDK pod.

How should I access the Google Analytics pod's headers in my app?

I have tried;

import GoogleAnalytics_iOS_SDK

In a Swift file, cocoapods 0.36 style. But there's no framework created anymore so no good.

#import <GoogleAnalytics_iOS_SDK/GAI.h>

In the bridging header, but doesn't work (no module map ?)


I have read that the behaviour for pods that only include headers in their 'sourse_files' changed in cocoapods 0.37 (see this commit). This appears to be in response to the problems that use_frameworks caused with these pods in 0.36 (see this SO question).

With this change in Cocoapod behaviour, the static library is integrated correctly (it wasn't with 0.36), the symbols are compiled into the app and available at runtime. But I don't have access to the headers.

Community
  • 1
  • 1
alexkent
  • 1,556
  • 11
  • 25

4 Answers4

28

This is a bug in Cocoapods 0.37.0. It has been logged in their tracker as issue #3499.

Workaround

  • Add $(SRCROOT)/Pods/GoogleAnalytics-iOS-SDK to the User Header Search Paths (set to Recursive) in the app target's Build Settings.
  • Reference the Google Analytics header directly in the Bridging Header with #import "GAI.h"
alexkent
  • 1,556
  • 11
  • 25
  • 4
    I'm very unhappy about having to add a bridging header just for this, but seems like this is the only valid option currently. – Eneko Alonso Jun 06 '15 at 17:56
  • Thanks, this saved me a bunch of time! – Joel Jul 08 '15 at 19:29
  • This issue might still be in CocoaPods 0.39.0, which I'm using at the moment. I added the User Header Search Paths and it works, but I can't seem to get the GGLContext to work for errors. Anyway, thanks a bunch, saved me a lot of hair since I was about to rip it all off in frustration. – ClockWise Oct 15 '15 at 11:50
  • What a mess. Answers by Fabric seems the better option now. – some_id Oct 24 '15 at 20:54
  • The Google analytics pod also causes lldb to break. After removing it, objects can be inpected and debugged as usual. – some_id Oct 24 '15 at 20:59
  • Worked for me, especially `#import "GAI.h"` part. – Maksim Oct 27 '15 at 14:23
3

Another trick is to add long relative path(s) to the bridging header.

This avoids having to make changes to project settings which may be overridden next time you run `pod install':

#import "../../Pods/GoogleAnalytics/Headers/Public/GAI.h"
#import "../../Pods/GoogleAnalytics/Headers/Public/GAIFields.h"
#import "../../Pods/GoogleAnalytics/Headers/Public/GAIDictionaryBuilder.h"

It also works when running your unit tests too, which another solution I tried didn't.

Chris
  • 39,719
  • 45
  • 189
  • 235
2

I don't know if this is the correct answer or not, but the way we got it to work was to manually import libGoogleAnalyticsServices.a and not via cocoapods.

Locate libGoogleAnalyticsServices.a and drag it into the project, then add it to Linked Frameworks and Libraries (if it's not there already) and you're good to go. Don't forget to remove it from your Podfile.

edit:
Don't forget to add the header files to your bridging-header

Simon
  • 1,076
  • 7
  • 13
  • Thanks, this is my contingency plan. I would like to get it working with Cocoapods, so I will leave the question open for a little longer. – alexkent May 04 '15 at 19:21
0

I had a similar problem on CocoaPods 0.39.0.

$(inherited) in build setting 'OTHER_LDFLAGS' solved it.

https://stackoverflow.com/a/32004207/3129306

Community
  • 1
  • 1
Jan F.
  • 1,681
  • 2
  • 15
  • 27