Cocoapods | podspec将GoogleAnalytics添加为依赖项

时间:2017-01-24 10:23:17

标签: swift3 google-analytics cocoapods podspec

我正在尝试将GoogleAnalytics添加为我的podspec中的依赖项,如下所示:

s.dependency "GoogleAnalytics"

我当然得到:

  

'Pods - ****'目标具有传递依赖关系,包括静态二进制文件:(**** / Pods / GoogleAnalytics / Libraries / libGoogleAnalytics.a)

由于Google并不打算提供其动态版本的pod,我试图通过在podspec中添加source_files / public_header_files / vendored_frameworks来添加它:

s.subspec 'GoogleAnalytics' do |sp|
  sp.source_files =
    'Pods/Google/Headers/*.h',
    'Pods/Google/Headers/ModuleHeaders/*.h',
    'Pods/FirebaseAnalytics/Frameworks/frameworks/FirebaseAnalytics.framework/Headers/*.h',
    'Pods/FirebaseInstanceID/Sources/*.h',
    'Pods/FirebaseInstanceID/Frameworks/frameworks/FirebaseInstanceID.framework/Headers/*.h',
    'Pods/GoogleInterchangeUtilities/Frameworks/frameworks/GoogleInterchangeUtilities.framework/Headers/*.h',
    'Pods/GoogleSymbolUtilities/Frameworks/frameworks/GoogleSymbolUtilities.framework/Headers/*.h',
    'Pods/GoogleToolboxForMac/*.h',
    'Pods/GoogleToolboxForMac/Foundation/*.h',
    'Pods/GoogleToolboxForMac/Foundation/*.m',
    'Pods/GoogleAnalytics/Libraries/*.a',
    'Pods/GoogleAnalytics/Sources/*.h'

  sp.ios.public_header_files  =
    'Pods/Google/Headers/*.h',
    'Pods/Google/Headers/ModuleHeaders/*.h',
    'Pods/FirebaseAnalytics/Frameworks/frameworks/FirebaseAnalytics.framework/Headers/*.h',
    'Pods/FirebaseInstanceID/Source/*.h',
    'Pods/FirebaseInstanceID/Frameworks/frameworks/FirebaseInstanceID.framework/Headers/*.h',
    'Pods/GoogleInterchangeUtilities/Frameworks/frameworks/GoogleInterchangeUtilities.framework/Headers/*.h',
    'Pods/GoogleSymbolUtilities/Frameworks/frameworks/GoogleSymbolUtilities.framework/Headers/*.h',
    'Pods/GoogleToolboxForMac/*.h',
    'Pods/GoogleToolboxForMac/Foundation/*.h',
    'Pods/GoogleAnalytics/Sources/*.h'

  sp.ios.vendored_frameworks =
    'Pods/Google/Frameworks/GGLAnalytics.framework',
    'Pods/Google/Frameworks/GGLCore.framework',
    'Pods/FirebaseAnalytics/Frameworks/frameworks/FirebaseAnalytics.framework',
    'Pods/FirebaseCore/Frameworks/frameworks/FirebaseCore.framework',
    'Pods/FirebaseInstanceID/Frameworks/frameworks/FirebaseInstanceID.framework',
    'Pods/GoogleInterchangeUtilities/Frameworks/frameworks/GoogleInterchangeUtilities.framework',
    'Pods/GoogleSymbolUtilities/Frameworks/frameworks/GoogleSymbolUtilities.framework'
end

我在我的项目中得到类似的内容:

pod“MyPod”

enter image description here

我在我的Bridging-Header中有这个:

#import <GGLCore/GGLCore.h>
#import <GGLAnalytics/GGLAnalytics.h>
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"

我尝试在AppDelegate中执行此操作:

// Configure tracker from GoogleService-Info.plist.
    var configureError:NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

        let gai = GAI.sharedInstance()
        gai?.trackUncaughtExceptions = true  // report uncaught exceptions
        gai?.logger.logLevel = GAILogLevel.verbose  // remove before app release

我仍然收到以下错误:

  

“_ OBJC_CLASS _ $ _ GAI”,引自:         AppDelegate.o中的objc-class-ref   ld:找不到架构x86_64的符号   clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

有没有人试图这样做?你成功了吗?感谢

1 个答案:

答案 0 :(得分:2)

与libGoogleAnalytics.a链接库为我解决了这个问题。

目标 - &gt;构建阶段 - &gt;链接二进制文件库, 从PathToGoogleAnalyticsFolder / GoogleAnalytics / Libraries /

添加文件

或在你的podspec中

s.dependency "GoogleAnalytics"
s.libraries = 'GoogleAnalytics',(any other libraries)
s.pod_target_xcconfig = { 'LIBRARY_SEARCH_PATHS' => '$(SRCROOT)/GoogleAnalytics/Libraries/' }

当然你可能不得不改变这条道路,但我希望这会有所帮助!