简体   繁体   English

无法使用Cocoapods 0.37,Swift,框架找到GoogleAnalytics-iOS-SDK的标题

[英]Can't find headers for GoogleAnalytics-iOS-SDK with Cocoapods 0.37, Swift, frameworks

Using cocoa pods 0.37.0 in a Swift project, with use_frameworks! 使用带有use_frameworks的Swift项目中的可可豆荚0.37.0! set in the podfile, I am unable to access the header files for the GoogleAnalytics-iOS-SDK pod. 在podfile中设置,我无法访问GoogleAnalytics-iOS-SDK pod的头文件。

How should I access the Google Analytics pod's headers in my app? 我应该如何在我的应用中访问Google Analytics广告管理系统的标题?

I have tried; 我试过了;

import GoogleAnalytics_iOS_SDK

In a Swift file, cocoapods 0.36 style. 在Swift文件中,cocoapods 0.36风格。 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) . 我已经读过,在'sourse_files'中只包含标题的pod的行为在cocoapods 0.37中发生了变化(参见本提交) This appears to be in response to the problems that use_frameworks caused with these pods in 0.36 (see this SO question) . 这似乎是为了回应use_frameworks在0.36中对这些pod造成的问题(参见此SO问题)

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. 随着Cocoapod行为的这种变化,静态库被正确集成(它不是0.36),符号被编译到应用程序中并在运行时可用。 But I don't have access to the headers. 但我无法访问标题。

This is a bug in Cocoapods 0.37.0. 这是Cocoapods 0.37.0中的一个错误。 It has been logged in their tracker as issue #3499 . 它已作为问题#3499记录在他们的跟踪器中。

Workaround 解决方法

  • Add $(SRCROOT)/Pods/GoogleAnalytics-iOS-SDK to the User Header Search Paths (set to Recursive) in the app target's Build Settings . $(SRCROOT)/Pods/GoogleAnalytics-iOS-SDK到应用程序目标的Build SettingsUser Header Search Paths (设置为递归)。
  • Reference the Google Analytics header directly in the Bridging Header with #import "GAI.h" 使用#import "GAI.h"直接在桥接标题中引用Google Analytics标题

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': 这样可以避免对下次运行“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. 它也适用于运行单元测试,我试过的另一个解决方案没有。

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. 我不知道这是否是正确的答案,但我们开始工作的方式是手动导入libGoogleAnalyticsServices.a而不是通过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. 找到libGoogleAnalyticsServices.a并将其拖到项目中,然后将其添加到Linked Frameworks and Libraries (如果它已经不存在)并且你很高兴。 Don't forget to remove it from your Podfile . 不要忘记将其从Podfile删除。

edit: 编辑:
Don't forget to add the header files to your bridging-header 不要忘记将头文件添加到桥接头

I had a similar problem on CocoaPods 0.39.0. 我在CocoaPods 0.39.0上遇到了类似的问题。

$(inherited) in build setting 'OTHER_LDFLAGS' solved it. 构建设置'OTHER_LDFLAGS'中的$(继承)解决了它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM