Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoapods | podspec add GoogleAnalytics as a dependency

I'm trying to add GoogleAnalytics as a dependency in my podspec like this :

s.dependency "GoogleAnalytics"

Of course I get :

The 'Pods-****' target has transitive dependencies that include static binaries: (****/Pods/GoogleAnalytics/Libraries/libGoogleAnalytics.a)

Since Google is not really going to give a dynamic version of their pod I'm trying to add it by adding source_files / public_header_files / vendored_frameworks in podspec :

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

I get something like this in my project where I do :

pod "MyPod"

enter image description here

I have this in my 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"

I try to do this in 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

I still get the following error :

"_OBJC_CLASS_$_GAI", referenced from: objc-class-ref in AppDelegate.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone already tried to do this ? And did you succeed ? Thanks

like image 399
Aximem Avatar asked Oct 29 '22 13:10

Aximem


1 Answers

Linking with libGoogleAnalytics.a Library fixed this issue for me.

Target->Build Phases-> Link Binary With Libraries, Add the file from PathToGoogleAnalyticsFolder/GoogleAnalytics/Libraries/

or in your podspec

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

Of course you may have to change that path, but I hope this helps!

like image 109
ImperialDre Avatar answered Nov 13 '22 06:11

ImperialDre