Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Linker command failed with exit code 1' when using Google Analytics via CocoaPods

I'm trying to add Google Analytics to an iOS app written in Swift. I've followed the guide that adds the frameworks via CocoaPods and added a bridging header but I'm still getting:

Linker command failed with exit code 1

My podfile does have use_frameworks! so I'm wondering if that has anything to do with it... there is no additional information on the Analytics site from what I can see.

EDIT: I've noticed that after viewing the full error message the following is displayed:

ld: '/Users/simon/Programming/VenueNow/Pods/GoogleUtilities/Libraries/libGTM_NSData+zlib.a(GTMNSData+zlib.o)' does not contain bitcode. 
You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

And searching for that issue brings up that Google updated to support bit code but hadn't updated the cocoa pods framework at that time.

like image 795
SimonTheEngineer Avatar asked Feb 09 '16 10:02

SimonTheEngineer


3 Answers

Go to your build settings and switch the target's settings to ENABLE_BITCODE = YES for now.

like image 174
dokun1 Avatar answered Nov 15 '22 16:11

dokun1


I had this same issue. Fortunately you can use Google Analytics with BitCode enabled, but it's a bit confusing due to how Google had set up their CocoaPods support.

There's actually 2 CocoaPods you can use:

  • 'Google/Analytics'
  • 'GoogleAnalytics'

The first one is the "latest" but it's tied to the greater Google pods so it does not support Bitcode. The second one is for Analytics only and does support BitCode. However because the latter does not include extra Google pods some of the instructions on how to set it up are incorrect.

You have to use the v2 method of setting up analytics:

// Inside AppDelegate:

// Optional: automatically send uncaught exceptions to Google Analytics.
GAI.sharedInstance().trackUncaughtExceptions = true

// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
GAI.sharedInstance().dispatchInterval = 20

// Create tracker instance.
let tracker = GAI.sharedInstance().trackerWithTrackingId("XX-XXXXXXXX-Y")

The rest of the Google analytics api you can use the v3 documentation (you don't need to use v2).

The 'Google/Analytics' cocoapod as of this writing still does not support BitCode. See here

like image 39
starlabs Avatar answered Nov 15 '22 14:11

starlabs


Had this issue, but it wasn't related to the bitcode setting. I had somehow ended up with duplicate framework files in the Frameworks folder of my XCode project. I deleted all frameworks files that were red (and duplicates). This solved the "Apple Mach O, Linker Command failed with exit code 1" error.

like image 7
lucius degeer Avatar answered Nov 15 '22 16:11

lucius degeer