Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker errors in a Swift project with Google Maps for iOS added via CocoaPods

I'm trying to add Google Maps SDK for iOS for a Swift project I'm working on via CocoaPods since CocoaPods now supports Swift.

Here's my podfile.

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '7.0'

pod 'Google-Maps-iOS-SDK'

Pod installation completes successfully and I could import the framework like this import GoogleMaps without any compilation errors.

But then I went ahead and added a UIView and set its class to GMSMapView and added a IBOutlet to my view controller and build the project. I get the following error.

Linker command failed with exit code 1 (use -v to see invocation)

enter image description here

I've added and used libraries written in Objective-C like MagicalRecord, MBProgressHUD on Swift projects without any issue.

I uploaded a demo Xcode project here as well.

Any way to resolve this?

like image 646
Isuru Avatar asked Feb 09 '15 07:02

Isuru


People also ask

What happened to Google Maps SDK for iOS?

By the time Apple stopped using Google’s map services, Google decided to create its own Maps SDK for all platforms, including iOS, and that way to compete the Map kit or any other map SDKs that other platforms use. Right now, Google consist of a strong player in this field, as many developers use that SDK.

What is gmsmapview in Swift?

The GMSMapView is part of the Google Maps framework, and actually it’s a UIView subclass. There’s one more modification needed to be done in that view, but this time we must go to the ViewController.swift file. At the top of the class you’ll find the following IBOutlet property declaration:

How to add Google Maps SDK to your project?

The Google Maps SDK needs several other frameworks to exist in the project in order to function properly. Before I give you the list of all the necessary frameworks and libraries that you have to add, make sure to select the project in the Project Navigator, then click to the Build Phases and expand the Link Binary With Libraries section.

How to add Google Maps to Xcode project navigator?

Then drag the GoogleMaps.framework from the Finder to the Project Navigator. When the Xcode asks you, make sure to select the Copy items if needed option, and of course, don’t forget to also check the GMapsDemo target as well: Next, go back to the Finder, and click to the GoogleMaps.framework once again.


2 Answers

The problem that you are facing is a combination of a bug on CocoaPods and a malformed podspec. Check this for more information.

Feel free to use this podspec:

https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json

... in your Podfile as:

pod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json"
like image 63
fz. Avatar answered Oct 08 '22 10:10

fz.


Response from a Google engineer:

I believe this bug is now fixed in 1.10.0. As part of moving to officially supporting CocoaPods we have changed the name of the Google Maps SDK for iOS CocoaPod. Please update your Podfile like this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.3'
use_frameworks!

pod 'GoogleMaps', '1.10.0'

(source of this information)

Note:

Nonetheless the fix above introduces a new warning, please see the following link.

So I personally recommend you staying with pod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json" until the bug will be fixed in a newer version of the Google Maps iOS SDK, or simply silencing this warning by adding -Wl,-no_compact_unwind in build settings flags.

like image 29
King-Wizard Avatar answered Oct 08 '22 10:10

King-Wizard