将pod与所有目标集成

col*_*ron 17 ios cocoapods xcode-project podfile

我使用我的iOS应用程序已经使用CocoaPods几周了,它与我测试的一个目标(我们称之为"MainApp")完美配合.但是,我现在想要构建一个不同的目标("MyAppLite"),并注意到构建失败(在其中一个pod的头文件中找不到文件).

我注意到的构建设置的差异如下:

  • 其他链接器标志不包含MyAppLite中所需的框架
  • MyAppLite中的框架/标题/库搜索路径都是空的
  • MyAppLite中不存在MainApp中的用户定义的构建设置

我怎样才能确保在运行时pod install,所有目标都链接了库?

作为参考,这是我的Podfile:

platform :ios, '5.0'

pod 'TTTAttributedLabel', '~> 1.7.0'
pod 'iRate', '~> 1.7.5'
pod 'MBProgressHUD', '~> 0.6'
pod 'FlurrySDK', '~> 4.2.3'
pod 'ACSimpleKeychain', '~> 0.0.1'
pod 'WEPopover', '~> 0.0.1'
pod 'AFNetworking', '~> 1.3.1'
pod 'Nimbus', '~> 1.0.0'
pod 'QuincyKit', '~> 2.1.9'
Run Code Online (Sandbox Code Playgroud)

Cœu*_*œur 35

对于CocoaPods 1.0.0,devs的建议正在使用abstract_target(但与0.39.0不兼容):

platform :ios, '5.0'

abstract_target 'defaults' do
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'

    target 'MyApp'
    target 'MyAppLite'
end
Run Code Online (Sandbox Code Playgroud)

对于CocoaPods 0.39.0 + 1.0.0兼容性,使用def工作正常(但不推荐使用开发人员):

platform :ios, '5.0'

def default_pods
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'
end

target 'MyApp' do
    default_pods
end

target 'MyAppLite' do
    default_pods
end
Run Code Online (Sandbox Code Playgroud)


Gab*_*lla 16

使用CocoaPods 0.x.

您可以使用该target指令

platform :ios, '13.0'


def default_pods
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'
end

target 'MyApp' do
  default_pods
end

target 'MyAppLite' do
  default_pods
end
Run Code Online (Sandbox Code Playgroud)

这将产生target,它将链接到targettarget.

相关文件:

  • 请注意,cocoapods会自动将podfile中的每个目标链接到您的项目.因此,目标的名称应该匹配.如果出于任何原因要在podfile中使用其他名称指定目标,则可以设置target属性:

    platform :ios, '13.0'
    
    
    def default_pods
        pod 'TTTAttributedLabel', '~> 1.7.0'
        pod 'iRate', '~> 1.7.5'
        pod 'MBProgressHUD', '~> 0.6'
        pod 'FlurrySDK', '~> 4.2.3'
        pod 'ACSimpleKeychain', '~> 0.0.1'
        pod 'WEPopover', '~> 0.0.1'
        pod 'AFNetworking', '~> 1.3.1'
        pod 'Nimbus', '~> 1.0.0'
        pod 'QuincyKit', '~> 2.1.9'
    end
    
    target 'MyApp' do
      default_pods
    end
    
    target 'MyAppLite' do
      default_pods
    end
    
    Run Code Online (Sandbox Code Playgroud)
  • 默认情况下,如果目标父级具有不同的平台,则它们是独占的.

  • Podfile的主要目标始终与最终项目的第一个目标相关联.


使用CocoaPods 1.x.

现在不支持Podfile中的link_with规范.

看到其他答案.

  • 这基本上就是我所做的,但我必须定义一个包含所有pod的显式目标,然后在pod列表之前使用`link_with ['MyApp','MyAppLite']行. (2认同)

lev*_*ese 7

如果你有大量的目标并且不想每次都添加新的目标,你可以使用这个

def common_pods

   pod 'TTTAttributedLabel', '~> 1.7.0'
   pod 'iRate', '~> 1.7.5'
   pod 'MBProgressHUD', '~> 0.6'
   pod 'FlurrySDK', '~> 4.2.3'
   pod 'ACSimpleKeychain', '~> 0.0.1'
   pod 'WEPopover', '~> 0.0.1'
   pod 'AFNetworking', '~> 1.3.1'
   pod 'Nimbus', '~> 1.0.0'
   pod 'QuincyKit', '~> 2.1.9'

end

project = Xcodeproj::Project.open “./<projectNameHere>.xcodeproj"

project.targets.each do |t|

target t.name do

    common_pods

end
Run Code Online (Sandbox Code Playgroud)