tech savvy
tech savvy

Reputation: 1435

Google/Analytics.h file not found when adding to AppDelegate

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?

Upvotes: 18

Views: 23150

Answers (9)

codaman
codaman

Reputation: 236

remove valid archs from build settings

Upvotes: 0

Farwa
Farwa

Reputation: 7064

  1. Run pod update
  2. Clean Build Files
  3. Run Project

Upvotes: 0

decades
decades

Reputation: 837

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>

Upvotes: 0

paul
paul

Reputation: 1142

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>

Upvotes: 46

sahara108
sahara108

Reputation: 2859

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

Upvotes: 2

christian mini
christian mini

Reputation: 1702

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

Upvotes: 0

Rajat Talwar
Rajat Talwar

Reputation: 11912

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

Upvotes: 6

John Bushnell
John Bushnell

Reputation: 1871

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.

Upvotes: 0

sabalaba
sabalaba

Reputation: 1294

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.)

Upvotes: 36

Related Questions