谷歌/分析。添加到AppDelegate时未找到的h文件。

时间:2021-12-08 15:18:43

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:

我正在尝试使用Cocoapods在我的ios项目中集成谷歌分析。但是,在导入谷歌/分析时,在接下来的步骤中添加配置文件到我的项目。在AppDelegate中,我得到了未找到文件的错误。尝试以下事情:

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

    在构建设置中添加$(SRCROOT)/ pod /GoogleAnalytics到用户头搜索路径。

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

    libGoogleAnalyticsServices补充道。在构建阶段,将二进制与库链接起来。

  3. Added -lGoogleAnalyticsServices in Other Linker Flags.

    在其他链接标记中添加-lGoogleAnalyticsServices。

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

不要真的想做2和3,因为它们可以让它从茧中解脱出来。

What exactly am I missing?

我到底错过了什么?

6 个解决方案

#1


31  

Problems

  1. The code examples on the official documentation suggest installing 1.0.0. Which doesn't even have binaries compiled for arm64.
  2. 官方文档中的代码示例建议安装1.0.0。它甚至没有为arm64编译的二进制文件。
  3. There seem to be at least three separate pods related to GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.
  4. 似乎至少有三个与遗传相关的独立的豆荚。GoogleAnalytics GoogleAnalytics-iOS-SDK,谷歌/分析。

Solution

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

将其添加到您的Podfile: pod '谷歌/Analytics',然后是pod安装。

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

这应该工作。现在您可以简单地导入谷歌/分析。h如在文档中所建议的:

#import <Google/Analytics.h>

#导入谷歌/ 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)

    当使用错误的建议pod版本(1.0.0)时,是一个64位兼容性问题。(ld:在架构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)

    当使用其他的pod (GoogleAnalytics- ios - sdk和GoogleAnalytics)时,我曾抱怨缺少 <谷歌 analytics。h> 头文件。(“谷歌/分析。h”未找到)

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

我在邮件列表中发现了这位先生的帖子,他建议谷歌/分析pod没有版本号。(pod '谷歌/Analytics)如上所述。)

#2


40  

Swift 3

斯威夫特3

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

3.17.0版本(在Podfile中安装pod 'GoogleAnalytics):

  1. Open yourproject.xcworkspace instead of yourproject.xcodeproj
  2. 开放的志愿者项目。xcworkspace代替yourproject.xcodeproj
  3. Use #import <GoogleAnalytics/GAI.h> in the bridging header file
  4. 使用#导入< GoogleAnalytics /丐。在桥接头文件中的h>。

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

编辑:jeremy piednoel的评论,你可能也需要。

#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>

#3


5  

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.

您需要添加$(SRCROOT)/ pod /谷歌和$(SRCROOT)/ pod /GoogleAnalytics,并使用递归选项到用户头搜索路径。

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

然后包括#import分析。h”而不是#导入

#4


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.

当您在构建设置中添加$(SRCROOT)/ pod /GoogleAnalytics到用户头搜索路径时,也可以选择递归选项。它将允许你的项目在GoogleAnalytics和它的所有子目录中搜索。

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.

更新:我已经尝试了教程,它可以很好地运行,没有任何额外的步骤。我的pod版本是0.35.0。当您创建配置文件时,请记住启用GoogleAnalytics服务。

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

更新:正如@RajatTalwar指出的,您还需要使用递归选项添加$(SRCROOT)/Pods/谷歌。然后包括#import分析。h”而不是#导入

#5


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.

如果有其他人在尝试导入 <谷歌 分析时出现错误。h> 和其他在线解决方案对你没有帮助,你应该继续读下去。

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.

我注意到在部署信息下的General选项卡上的项目有一个不同,第二个目标(工作的那个)对iPhone和iPad有单独的选项,但是第一个目标没有。网上的另一个人说,当他们复制他们的目标时,他们收到了这两个新选项。我的第二个目标也是第一个目标的副本。

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.

长话短说,我发现,如果我复制我的目标,复制现在突然生效。那些单独的iPhone和iPad的选择也奇迹般地出现了。所以我认为我的项目目标是非标准的,造成了一个问题,可能是因为这个项目是很久以前创建的。

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

然后,我删除了原来的目标,并将新的目标重新命名为相同的名称,尽管在与plist文件相关的构建设置中需要进行一些清理工作(它生成了一个副本)。plist文件)。

Hope this helps someone.

希望这可以帮助别人。

#6


0  

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

检查你是否有多个目标,在此情况下,在你的pod文件中添加pod '谷歌/Analytics' foreach目标:

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

#1


31  

Problems

  1. The code examples on the official documentation suggest installing 1.0.0. Which doesn't even have binaries compiled for arm64.
  2. 官方文档中的代码示例建议安装1.0.0。它甚至没有为arm64编译的二进制文件。
  3. There seem to be at least three separate pods related to GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.
  4. 似乎至少有三个与遗传相关的独立的豆荚。GoogleAnalytics GoogleAnalytics-iOS-SDK,谷歌/分析。

Solution

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

将其添加到您的Podfile: pod '谷歌/Analytics',然后是pod安装。

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

这应该工作。现在您可以简单地导入谷歌/分析。h如在文档中所建议的:

#import <Google/Analytics.h>

#导入谷歌/ 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)

    当使用错误的建议pod版本(1.0.0)时,是一个64位兼容性问题。(ld:在架构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)

    当使用其他的pod (GoogleAnalytics- ios - sdk和GoogleAnalytics)时,我曾抱怨缺少 <谷歌 analytics。h> 头文件。(“谷歌/分析。h”未找到)

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

我在邮件列表中发现了这位先生的帖子,他建议谷歌/分析pod没有版本号。(pod '谷歌/Analytics)如上所述。)

#2


40  

Swift 3

斯威夫特3

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

3.17.0版本(在Podfile中安装pod 'GoogleAnalytics):

  1. Open yourproject.xcworkspace instead of yourproject.xcodeproj
  2. 开放的志愿者项目。xcworkspace代替yourproject.xcodeproj
  3. Use #import <GoogleAnalytics/GAI.h> in the bridging header file
  4. 使用#导入< GoogleAnalytics /丐。在桥接头文件中的h>。

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

编辑:jeremy piednoel的评论,你可能也需要。

#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>

#3


5  

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.

您需要添加$(SRCROOT)/ pod /谷歌和$(SRCROOT)/ pod /GoogleAnalytics,并使用递归选项到用户头搜索路径。

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

然后包括#import分析。h”而不是#导入

#4


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.

当您在构建设置中添加$(SRCROOT)/ pod /GoogleAnalytics到用户头搜索路径时,也可以选择递归选项。它将允许你的项目在GoogleAnalytics和它的所有子目录中搜索。

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.

更新:我已经尝试了教程,它可以很好地运行,没有任何额外的步骤。我的pod版本是0.35.0。当您创建配置文件时,请记住启用GoogleAnalytics服务。

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

更新:正如@RajatTalwar指出的,您还需要使用递归选项添加$(SRCROOT)/Pods/谷歌。然后包括#import分析。h”而不是#导入

#5


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.

如果有其他人在尝试导入 <谷歌 分析时出现错误。h> 和其他在线解决方案对你没有帮助,你应该继续读下去。

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.

我注意到在部署信息下的General选项卡上的项目有一个不同,第二个目标(工作的那个)对iPhone和iPad有单独的选项,但是第一个目标没有。网上的另一个人说,当他们复制他们的目标时,他们收到了这两个新选项。我的第二个目标也是第一个目标的副本。

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.

长话短说,我发现,如果我复制我的目标,复制现在突然生效。那些单独的iPhone和iPad的选择也奇迹般地出现了。所以我认为我的项目目标是非标准的,造成了一个问题,可能是因为这个项目是很久以前创建的。

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

然后,我删除了原来的目标,并将新的目标重新命名为相同的名称,尽管在与plist文件相关的构建设置中需要进行一些清理工作(它生成了一个副本)。plist文件)。

Hope this helps someone.

希望这可以帮助别人。

#6


0  

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

检查你是否有多个目标,在此情况下,在你的pod文件中添加pod '谷歌/Analytics' foreach目标:

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