Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics in iOS 8 using Swift don't work

I have integrated Google Analytics library to my project.

Then I configured the bridging header file and I've added the following headers Google Analytics

#import "Libraries/GoogleAnalytics/GAI.h"
#import "Libraries/GoogleAnalytics/GAIFields.h"
#import "Libraries/GoogleAnalytics/GAILogger.h"
#import "Libraries/GoogleAnalytics/GAITracker.h"
#import "Libraries/GoogleAnalytics/GAIDictionaryBuilder.h"

The initialization of the library in the AppDelegate.swift compiles and runs correctly. I add the following code to track an event

var tracker = GAI.sharedInstance().defaultTracker
tracker.send(GAIDictionaryBuilder.createEventWithCategory(category, action: action, label: label, value: value).build())

When trying to generate the build, the following error occurs

Undefined symbols for architecture x86_64:
  "_NSOverwriteMergePolicy", referenced from:
    -[GAIDataStore contextWithModel:URL:] in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_NSSQLiteErrorDomain", referenced from:
    -[GAIDataStore performBlockAndWait:withError:] in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_NSSQLiteStoreType", referenced from:
    -[GAIDataStore coordinatorWithModel:URL:] in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_OBJC_CLASS_$_NSAttributeDescription", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAICoreDataUtil.o)
  "_OBJC_CLASS_$_NSEntityDescription", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAIDataStore.o)
    objc-class-ref in libGoogleAnalyticsServices.a(GAICoreDataUtil.o)
  "_OBJC_CLASS_$_NSFetchRequest", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_OBJC_CLASS_$_NSManagedObjectContext", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_OBJC_CLASS_$_NSManagedObjectModel", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAICoreDataUtil.o)
  "_OBJC_CLASS_$_NSPersistentStoreCoordinator", referenced from:
    objc-class-ref in libGoogleAnalyticsServices.a(GAIDataStore.o)
  "_SCNetworkReachabilityCreateWithName", referenced from:
    _kDefaultReachabilityApi in libGoogleAnalyticsServices.a(GAIReachabilityChecker.o)
  "_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
    _kDefaultReachabilityApi in libGoogleAnalyticsServices.a(GAIReachabilityChecker.o)
  "_SCNetworkReachabilitySetCallback", referenced from:
    _kDefaultReachabilityApi in libGoogleAnalyticsServices.a(GAIReachabilityChecker.o)
  "_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
    _kDefaultReachabilityApi in libGoogleAnalyticsServices.a(GAIReachabilityChecker.o)
  "_deflate", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_deflateEnd", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_deflateInit2_", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflate", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflateEnd", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflateInit2_", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm using Xcode 6 GM and try to compile the application running in the iPhone 5s simulator.

EDIT1:

Libraries required had already been added

  • CoreData.framework
  • SystemConfiguration.framework
  • libz.dylib

I have partially solved the error adding in bridging header file the following imports

#import <CoreData/CoreData.h>
#import <SystemConfiguration/SystemConfiguration.h>

The error message is reduced to

Undefined symbols for architecture x86_64:
  "_deflate", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_deflateEnd", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_deflateInit2_", referenced from:
    +[GAICompressionUtil gai_dataByCompressingBytes:length:compressionLevel:mode:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflate", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflateEnd", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
  "_inflateInit2_", referenced from:
    +[GAICompressionUtil gai_dataByInflatingBytes:length:isRawData:] in libGoogleAnalyticsServices.a(GAICompressionUtil.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT2:

Finally I solved the problem.

In Target Settings -> Build Settings -> Linking -> Other Linker Flags add the following flag: -lz

like image 537
Ezequiel Dittler Avatar asked Sep 16 '14 15:09

Ezequiel Dittler


People also ask

What is Google Analytics in Swift?

Google Analytics collects usage and behavior data for your web app. The SDK logs two primary types of information: Events: What is happening in your app, such as user actions, system events, or errors.


2 Answers

@Ezequiel Perez : You have to include the targets linked libraries.

CoreData.framework
SystemConfiguration.framework
libz.dylib

Try including this....

like image 75
Suresh Kumar Durairaj Avatar answered Sep 29 '22 09:09

Suresh Kumar Durairaj


You have to add all the Objective-C libraries GA needs explicitly.

In the error output you can see that it is looking for Core Data but instead finds "undefined symbols". That shows you that it is missing the library. Notice that the Objective-C libraries are distinct from the modules you import in Swift.

To solve this, go to build phases of your target and link to the necessary libraries, starting with CoreData.framework. Consult the GA documentation on which other libraries you need.

EDIT:

I made a quick app, added GA and made it work by adding the libraries. Maybe you could try removing the libs.dylib library and re-adding it. I also recommend to just include the headers by name

#include "GAI.h"
like image 37
Mundi Avatar answered Sep 29 '22 11:09

Mundi