Reputation: 1435
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:
Added $(SRCROOT)/Pods/GoogleAnalytics
to User Header Search Paths in Build Settings.
Added libGoogleAnalyticsServices.a
to link binary with libraries in build phases.
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
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.pxbproj
and 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
Reputation: 1142
Swift 3
With version 3.17.0 (installed using pod 'GoogleAnalytics' in Podfile):
#import <GoogleAnalytics/GAI.h>
in the bridging header fileEdit: Per jeremy piednoel's comment you may also need
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Upvotes: 46
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
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
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
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
Reputation: 1294
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>
There were two sets of issues that I ran into:
When using the incorrect suggested pod version (1.0.0), was a 64-bit compatibility issue. (ld: symbol(s) not found for architecture arm64
)
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