Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CocoaPods: How to build each subspec as its own framework target

I'm having trouble creating a CocoaPods .podspec file for my project so that it builds with the same module structure when installed by CocoaPods as it does in the original project.

I'm building an SDK that contains several frameworks:

MyThingSDK.xcodeproj
  -> Target: Framework "Core.framework"
             Builds files in MyThing/Core/*.swift
  -> Target: Framework "Designer.framework"
             Builds files in MyThing/Designer/*.swift
  -> Target: Framework "Runner.framework"
             Builds files in MyThing/Runner/*.swift

At the end of building this I have three frameworks named after each target

MyThingSDK.podspec looks like:

Pod::Spec.new do |s|

  s.name         = "MyThingSDK"
  s.version      = "0.1.1"
  ...

  s.subspec "Core" do |spec|
    spec.source_files   = "MyThing/Core/**/*.{h,m,swift}"
    spec.public_header_files = "MyThing/Core/*.{h}"
    spec.header_dir = "Core"
  end

  s.subspec "Designer" do |spec|
    spec.source_files   = "MyThing/Designer/**/*.{h,m,swift}"
    spec.public_header_files = "MyThing/Designer/*.{h}"
    spec.header_dir = "Designer"
    spec.dependency "MyThing/Core"
  end

  s.subspec "Runner" do |spec|
    spec.source_files   = "MyThing/Runner/**/*.{h,m,swift}"
    spec.public_header_files = "MyThing/Runner/**/*.{h}"
    spec.header_dir = "Runner"
    spec.dependency "MyThing/Core"
  end

end

When I consume this in a client project using pod install, I end up with this structure:

ClientProject.xcworkspace
  ClientProject.xcproject
  Pods.xproject
    -> Target: Framework "MyThingSDK.framework"
               Builds files from MyThing/Core/*.swift
               Builds files from MyThing/Designer/*.swift
               Builds files from MyThing/Runner/*.swift

The Podfile refers to the SDK like this:

pod 'MyThingSDK', :path => '/Volumes/Dev/src/MyThingSDK'

So when CocoaPods creates its Pods project, all the source files go into a single framework instead of each subspec having their own framework. This creates duplicate definition problems. Suppose both Designer and Runner have a class called "Client" -- that's fine while they are separate frameworks, but not when they get merged into one.

How can I keep one framework per subspec?

like image 757
Ben Avatar asked Aug 17 '18 15:08

Ben


1 Answers

One of the main purposes of subspecs is to enable configuration of a single framework. If you want separate frameworks, you should use a separate podspec for each one.

like image 55
Paul Beusterien Avatar answered Oct 23 '22 09:10

Paul Beusterien