将pod与所有目标集成

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

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

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

如何确保在运行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' 

使用CocoaPods 0.x.

您可以使用link_with指令

 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' link_with "MyApp" link_with "MyAppLite" 

这将产生libPods.a并将它链接到Target1Target1

相关文件 :

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

     target :test, :exclusive => true do link_with 'MyAppTests' end 
  • 默认情况下,如果目标父级具有不同的平台,则它们是独占的。

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


使用CocoaPods 1.x.

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

看到其他答案。

对于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 

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

 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 

来自文档:

如果未指定显式目标,则Pods目标将与项目中的第一个目标链接。

您可以使用link_with链接其他目标。

如果您需要针对不同目标的不同依赖关系配置,请参阅Cocoapods文档中的多个目标

如果您有大量目标并且不想每次都添加新目标,则可以使用此目标

 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 “./.xcodeproj" project.targets.each do |t| target t.name do common_pods end