简体   繁体   English

CocoaPods:如何将每个子规范构建为自己的框架目标

[英]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.我在为我的项目创建 CocoaPods .podspec 文件时遇到问题,以便它在由 CocoaPods 安装时使用与原始项目中相同的模块结构构建。

I'm building an SDK that contains several frameworks:我正在构建一个包含多个框架的 SDK:

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: MyThingSDK.podspec 看起来像:

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:当我使用 pod install 在客户端项目中使用它时,我最终得到了这个结构:

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: Podfile 像这样引用 SDK:

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.所以当 CocoaPods 创建它的 Pods 项目时,所有的源文件都进入一个单一的框架,而不是每个子规范都有自己的框架。 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.假设 Designer 和 Runner 都有一个名为“Client”的类——当它们是单独的框架时这很好,但当它们合并为一个时就不行了。

How can I keep one framework per subspec?如何为每个子规范保留一个框架?

One of the main purposes of subspecs is to enable configuration of a single framework. subspecs 的主要目的之一是启用单个框架的配置。 If you want separate frameworks, you should use a separate podspec for each one.如果你想要单独的框架,你应该为每个框架使用单独的 podspec。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM