18

I am trying to integrate Google Analytics in my ios project using Cocoapods. However, after following this for the steps till adding configuration file to my project, when importing the Google/Analytics.h in AppDelegate I get error for file not found. Tried following things:

  1. Added $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings.

  2. Added libGoogleAnalyticsServices.a to link binary with libraries in build phases.

  3. Added -lGoogleAnalyticsServices in Other Linker Flags.

Don't really want to do 2 and 3 as they make it free from Cocoapods.

What exactly am I missing?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
tech savvy
  • 1,417
  • 4
  • 21
  • 42

9 Answers9

46

Swift 3

With version 3.17.0 (installed using pod 'GoogleAnalytics' in Podfile):

  1. Open yourproject.xcworkspace instead of yourproject.xcodeproj
  2. Use #import <GoogleAnalytics/GAI.h> in the bridging header file

Edit: Per jeremy piednoel's comment you may also need

#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
paul
  • 1,132
  • 11
  • 12
36

Problems

  1. The code examples on the official documentation suggest installing 1.0.0. Which doesn't even have binaries compiled for arm64.
  2. There seem to be at least three separate pods related to GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.

Solution

Add this to your Podfile: pod 'Google/Analytics' and then pod install.

That should work. Now you can simply import Google/Analytics.h as suggested in the docs:

#import <Google/Analytics.h>

Further Discussion

There were two sets of issues that I ran into:

  1. When using the incorrect suggested pod version (1.0.0), was a 64-bit compatibility issue. (ld: symbol(s) not found for architecture arm64)

  2. When using the other pods (GoogleAnalytics-iOS-SDK and GoogleAnalytics) I had complaints of a missing <Google/Analytics.h> header file. ("Google/Analytics.h" not found)

I found this gentleman's post on a mailing list which suggested the Google/Analytics pod with no version number. (pod 'Google/Analytics' as noted above.)

sabalaba
  • 1,296
  • 12
  • 17
6

This is a bug in cocoapods.

you need to add $(SRCROOT)/Pods/Google and $(SRCROOT)/Pods/GoogleAnalytics with recursive option to your User Header Search Paths.

Then include the #import "Analytics.h" instead of #import

Rajat Talwar
  • 11,922
  • 1
  • 18
  • 12
2

When you add $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings, also select recursive option. It will allow your project to search in GoogleAnalytics and all of its sub-directories.

UPDATED: I have tried the tutorial and it works fine without any extra step. My pod version is 0.35.0. When you create configuration file, remember to enable GoogleAnalytics service.

UPDATED: As @RajatTalwar pointed out, you also need to add $(SRCROOT)/Pods/Google with recursive option. Then include the #import "Analytics.h" instead of #import

sahara108
  • 2,829
  • 1
  • 22
  • 41
0

If anyone else out there is having an error with trying to #import <Google/Analytics.h>, and the other solutions online aren't helping you, you should read on.

I was having this problem and none of the solutions I found would fix it. Then I noticed that one of my targets worked while the other one did not (I had two in the same project), and I tried to track down what was the difference between the two targets.

I noticed that there was a difference in the project on the General tab under Deployment info, where the second target (the one which worked) had separate options for iPhone and iPad, but the first did not. Someone else online said that they received these two new options when they duplicated their target. My second target was also a duplicate of the first, originally.

To make a long story short, I found that if I duplicated my target that the duplicate now suddenly worked. Those separate iPhone and iPad options also magically appeared. So I guess my project target was non-standard and causing a problem, probably because this project was created a long time ago.

I then just deleted the original target and renamed the new one to be the same name, although there was some cleanup work required in the build settings related to the plist file (it made a copy.plist file).

Hope this helps someone.

John Bushnell
  • 1,851
  • 22
  • 29
0

Check if you have multiple targets, in this case add pod 'Google/Analytics' foreach target in you pod file:

def google_pods
pod 'Google/Analytics'
end

target 'target 1' do
    google_pods
end

target 'target 2' do
    google_pods
end

target 'target N' do
    google_pods
end
christian mini
  • 1,662
  • 20
  • 39
0

Also my $0.02 to this, since it seems to be a never ending story. None of the suggestions above did help. I got this obscure message from pod install

[!] The `blabla [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-blabla/Pods-blabla.release.xcconfig'. This can lead to problems with the CocoaPods installation

Finally I inspected my project.pxbprojand found, that I had this entry:

HEADER_SEARCH_PATHS = "";`

Obviously this is treated as "defined", so I changed it to

HEADER_SEARCH_PATHS = "$(inherited)";

and boom - all the Google suggested includes work

#import <GoogleAnalytics/GAI.h>
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
decades
  • 827
  • 17
  • 25
0
  1. Run pod update
  2. Clean Build Files
  3. Run Project
Farwa
  • 6,156
  • 8
  • 31
  • 46
0

remove valid archs from build settings

codaman
  • 206
  • 4
  • 6