9

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?

Isuru
  • 30,617
  • 60
  • 187
  • 303
  • I'm trying to replicate this issue, but I'm currently getting the following error from pod update: `[!] Invalid \`Podfile\` file: undefined method \`use_frameworks!' for #. Updating CocoaPods might fix the issue.` – Brett Feb 11 '15 at 00:43
  • @Brett Hi, I'm using CocoaPods 0.36 beta 1. I think that command was removed in beta 2 which is the current version. You would have to [downgrade](http://stackoverflow.com/a/20489489/1077789) to beta 1 (`sudo gem install cocoapods -v 0.36.0.beta.1`) to install this because without that command, the Objective-C pods get installed as static libraries instead of Frameworks. Since Google Maps SDK is also a Objective-C library, you need that command. I explained this a little further in a [blog post](http://iosdevbits.blogspot.com/2014/12/finally-cocoapods-with-swift.html) I wrote. – Isuru Feb 11 '15 at 07:25
  • I was building with CocoaPods 0.35 (release). I've just uninstalled cocoapods release and installed `cocoapods-0.36.0.beta.2`. I used my github sample to test this new configuration (after removing `Podfile.lock` and `Pods/*`) and it all worked swimmingly. I read your blog post, and I don't understand why you need the `use_frameworks!` to get Google Maps SDK for iOS to work with Swift. – Brett Feb 12 '15 at 00:52
  • @Brett Of course the Maps SDK works that way. I have used it in a different project myself. I was going to take a more "pure" Swift approach by adding the SDK as a framework without using a bridging headers and all. It normally works well with other Objective-C libraries. – Isuru Feb 12 '15 at 04:31
  • I'm going to need pointers to technical documentation on what is required on our end to make this work. I'm not turning up anything useful in my searches of the cocoapods site. Help? – Brett Feb 12 '15 at 06:29
  • Here's an example of using Google Maps SDK for iOS with Swift: https://github.com/domesticmouse/swift-google-map – Brett Feb 11 '15 at 02:47
  • @Brett According to [this answer](http://stackoverflow.com/a/28471830/1077789) posted here, the actual issue seems to be a bug in CocoaPods. But the changes that needs to be done for the podspec should be done from your end, I suppose. – Isuru Feb 22 '15 at 05:32
  • Simple Solution Go to Target ->Linking -> other linker Flag and add $(inherited) in other linker flag in both Debug and Release. – Mihir Oza Feb 03 '16 at 11:13

2 Answers2

7

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"
fz.
  • 3,233
  • 22
  • 20
  • Hi, I just tried this. The pod installation is successful but the Targets list only shows **Pods** in the Pods project. – Isuru Feb 12 '15 at 09:25
  • Can you clarify what you mean by that? – fz. Feb 12 '15 at 16:43
  • The library gets installed [successfully](http://i.imgur.com/QUgX7pb.png). But in the [Targets](http://i.imgur.com/ufAxMos.png) of the Pods project, there is no framework added. – Isuru Feb 14 '15 at 13:40
  • @isuru Yes it does. Can you post your project and/or Podfile somewhere? – fz. Feb 20 '15 at 23:54
  • I uploaded an Xcode project to my dropbox [here](https://www.dropbox.com/s/05voozh1upeuvc4/GoogleMapsPod.zip?dl=0). – Isuru Feb 21 '15 at 15:51
  • 1
    @Isuru Your project is working fine. Have you try to `import GoogleMaps` from your swift files?. The fact that it's not a target is the correct behavior because Google Maps is already a framework compressed in a zip file. – fz. Feb 22 '15 at 04:11
  • Yep, you're right. I just tried it and it works. My bad. Thanks so much. Google SDKs are not playing nice with CocoaPods for Swift, it seems. I face another [issue](http://stackoverflow.com/q/28130394/1077789) with their iOS SDK for Google Plus too. – Isuru Feb 22 '15 at 05:30
  • Thank you so much @fz. for this Podspec! I was also having errors when including the Google Maps iOS SDK in my Swift pod, but your version of the Podspec finally solved them! – Romain Mar 09 '15 at 07:51
  • Issue created in Google Maps iOS SDK bug reporter: https://code.google.com/p/gmaps-api-issues/issues/detail?id=8082&thanks=8082&ts=1432135423 – King-Wizard May 20 '15 at 15:27
2

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.

Michael Kohne
  • 11,888
  • 3
  • 47
  • 79
King-Wizard
  • 15,628
  • 6
  • 82
  • 76