0

I'm creating my first CocoaPod project (ObjC) which requires a Swift dependency. When I try to lint the project I get the error:

Pods written in Swift can only be integrated as frameworks; add use_frameworks! to your Podfile or target to opt into using it.

I understand how to do this when including a CocoaPod in a regular xcode project, but how do I solve this issue when the project is a CocoaPod? I tried adding the 'use_frameworks!' declaration in the podspec file but that doesn't seem to be correct.

Here is my podspec file:

Pod::Spec.new do |s|

  s.name             = "my-custom-pod"
  s.version          = "0.0.1"
  s.summary          = "totally awesome stuff"

  s.description      = <<-DESC
                         more details about the totally awesome stuff, if only it worked :(
                       DESC

  s.homepage         = "https://awesomestuff.com"
  # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
  s.license          = 'MIT'
  s.author           = { "Me" => "me@awesomestuff.com" }
  s.source           = { :git => "https://awesome.com/awesome/my-custom-pod.git", :tag => s.version.to_s }
  s.social_media_url = 'https://twitter.com/awesomestuff'

  s.platform     = :ios, '8.0'
  s.requires_arc = true

  s.source_files = 'Pod/Classes/**/*'
  s.resource_bundles = {
    'my-custom-pod' => ['Pod/Assets/*.png']
  }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  s.frameworks = 'CoreLocation', 'MapKit'
  s.dependency 'SSKeychain', '~> 1.2.3'
  s.dependency 'FMDB', '~> 2.5'
  s.dependency 'GoogleMaps', '~> 1.10.4'
  s.dependency 'Socket.IO-Client-Swift', '~> 4.0.4'
end

Here, the socket io client is the issue. I'm able to import the socket io framework into my other ObjC projects no problem, but I've never tried to do it into a custom cocoa pod.

Any help is much appreciated. Thanks in advance.

Warblr
  • 1,188
  • 1
  • 13
  • 27

3 Answers3

1

use_frameworks! is a podfile-only setting.

The way to use frameworks while linting a podspec is to provide the --use-frameworks flag to your pod spec lint command.

pevasquez
  • 862
  • 8
  • 14
  • Thanks for responding, @pevasquez ! I was using the --use-frameworks flag when linting because I was also using the GoogleMaps framework, but I was still getting the error related to the Socket IO framework being Swift. – Warblr Feb 11 '16 at 02:29
  • Correction, `--use-frameworks` is not a valid lint command. `--use-libraries` is perhaps what you were referring to? That doesn't seem to fix the issue though; again, I was using that previously due to the GoogleMaps dependency. – Warblr Feb 11 '16 at 18:43
  • Well, you're right, ```--use-frameworks``` is no more a flag for lint, as it's the default behavior now. ```--use-libraries``` means just the opposite to that, so try without it and see how you go. No Swift dependency wil work with that flag – pevasquez Feb 12 '16 at 12:25
  • Thanks again, pevasquez. That was part of the issue. Will summarize below. – Warblr Feb 12 '16 at 16:40
1

Add in podsepc file :-

spec.dependency 'Socket.IO-Client-Swift', '12.0.0'

  spec.pod_target_xcconfig   = {

    'SWIFT_VERSION' => '4.0',
    'VALID_ARCHS' => 'x86_64 arm64'
  }
SHR
  • 7,940
  • 9
  • 38
  • 57
0

The lint was failing because I was trying to include the --use-libraries lint command to accommodate the GoogleMaps pod but this is not compatible when trying to include a swift pod like Socket.IO. Because the GoogleMaps pod includes a static version of itself within the pod you cannot simply include it in your pod project otherwise you get the lint error The 'Pods' target has transitive dependencies that include static binaries

So I ended up having to grab the GoogleMaps.framework and include it statically in my pod (as opposed to listing the pod as a dependency). Not ideal but I can't find another working solution to include both a swift pod and the GoogleMaps pod.

Here are the relevant bits from my podspec file:

s.libraries = 'c++', 'icucore', 'z'

s.dependency 'SSKeychain', '~> 1.2.3'
s.dependency 'FMDB', '~> 2.5'
s.dependency 'Socket.IO-Client-Swift', '~> 5.3.3'

s.frameworks = 'MapKit', 'GoogleMaps', 'AVFoundation', 'CoreData','CoreLocation', 'CoreText', 'GLKit', 'ImageIO', 'OpenGLES', 'QuartzCore', 'SystemConfiguration', 'Accelerate'
s.resource_bundles = { 'GoogleMaps' => ['Pod/Dependencies/GoogleMaps.framework/Resources/*.bundle'] }
s.vendored_frameworks = 'Pod/Dependencies/GoogleMaps.framework'
s.xcconfig = { 'LD_RUNPATH_SEARCH_PATHS' => 'Pod/Dependencies' }

And here is the lint command that works with this podspec:

pod lib lint my-custom-pod.podspec --private --allow-warnings

The only issue I'm seeing now is when I import the pod into my project I'm either stuck with this warning prior to runtime:

Auto-Linking supplied 'path/to/GoogleMaps.framework/GoogleMaps', framework linker option at path/to/Pod/Dependencies/GoogleMaps.framework/GoogleMaps is not a dylib

Or this one at compile time (shows in console):

Class GMSBillingPointRecorder is implemented in both path/to/my/application/Frameworks/my-custom-pod.framework/my-custom-pod and path/to/my/app/myapp.app/myapp. One of the two will be used. Which one is undefined.

Where there is a separate console log warning like this for every Class in the GoogleMaps framework. I cannot seem to get rid of these warnings. If I link I get a warning, if I don't link I get warnings.

Warblr
  • 1,188
  • 1
  • 13
  • 27