【问题标题】:Integrating pods with all targets将 pod 与所有目标集成
【发布时间】:2019-11-23 20:51:40
【问题描述】:

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

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

  • 其他链接器标志不包含 MyAppLite 中所需的框架
  • Framework/Header/Library Search Paths 在 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'

【问题讨论】:

    标签: ios cocoapods podfile xcode-project


    【解决方案1】:

    对于 CocoaPods 1.0.0,开发人员的建议是使用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 可以正常工作(但开发人员不推荐):

    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
    

    【讨论】:

      【解决方案2】:

      使用 CocoaPods 1.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
      

      相关documentation

      【讨论】:

      • 这基本上是我所做的,但我必须定义一个包含所有 pod 的显式目标,然后在 pod 列表之前添加 link_with ['MyApp', 'MyAppLite'] 行。
      • 我能问你为什么要这样做吗?
      • 是的,可能是一个不相关的错字或什么的。现在效果很好。
      • 请注意版本 1.2.0,这不再有效。 [!] 无效的Podfile 文件:[!] Podfile 中link_with 的规范现在不支持,请改用目标块..
      • 这个answer 为我工作
      【解决方案3】:

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

      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
      

      【讨论】:

      • 嗨,它不工作。它给出错误:[!] Invalid Podfile` 文件:语法错误,意外的输入结束,预期结束。`
      【解决方案4】:

      来自文档:

      如果没有明确指定目标,那么 Pods 目标将与项目中的第一个目标链接。

      您可以使用link_with 链接更多目标。

      如果您需要针对不同目标的不同依赖项配置,另请参阅 Cocoapods 文档中的 Multiple Targets

      【讨论】:

      • 构建设置是使用 pod install 自动设置的——我不想手动开始处理应该正确自动生成的东西——这不是 CocoaPods 的重点吗?
      • 另外,我想为所有目标设置完全相同的依赖关系。
      猜你喜欢
      • 2018-01-10
      • 2013-04-20
      • 2011-12-07
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多