使用现有静态库和iOS应用程序配置Cocoapods [英] Configuring Cocoapods with an existing static library and iOS application

查看:245
本文介绍了使用现有静态库和iOS应用程序配置Cocoapods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用Cocoapods正确编译我的工作区。工作区中有3个项目,每个项目都有自己的目标:

I'm having trouble getting my workspace to compile correctly with Cocoapods. There are 3 projects in the workspace, each with their own target:


  1. libPods - 具有所有外部依赖关系的Cocoapods静态库

  2. libCommon - 我的静态库,我保存所有共享代码(基本控制器,网络代码,常用UI等)

  3. myApp - 我的iOS应用程序

libCommon和myApp都需要libPods的外部依赖项。最初我觉得它会这样工作:

Both libCommon and myApp require the external dependencies from the libPods. Originally I thought it would work like this:


  1. libPods builds

  2. libCommon链接libPods和build

  3. myApp与libCommon和build的链接

在这种情况下,libCommon拥有pod,然后myApp只是链接libCommon,就像我一直在做Cocoapods ...但显然静态库不喜欢与静态库链接(我有一堆动态库错误)。我在一个github问题上阅读,而不是我应该构建libPods和libCommon,然后myApp应该链接到两个库。现在我的podfile看起来像这样:

In this scenario libCommon "owns" the pods, and then then myApp just links against libCommon like I've always done pre-Cocoapods... but apparently static libraries don't like to be linked with static libraries (I got a bunch of dynamic library errors). I read on a github issue somewhere that instead I should build libPods and libCommon and then myApp should link against both libraries. Right now my podfile looks something like this:

workspace 'MyApp.xcworkspace'
platform :ios, '5.0'

link_with ['Common', 'MyApp']

target 'MyApp' do
  xcodeproj 'MyApp.xcodeproj'

  pod 'AFNetworking',               '1.1.0'
  pod 'TTTAttributedLabel',         '1.6.0'
  pod 'JSONKit',                    '1.5pre'
  pod 'Reachability',               '3.1.0'
end

通过此设置,myApp拥有所有pod,然后在libCommon构建中设置我指定了pod标头的路径。这构建正常,直到我尝试使用libCommon中的一个类。一旦我这样做,我得到其中一个 _OBJC_CLASS _ $ _ Blah 错误(告诉我虽然标题可用,但它仍然没有正确链接)。当我尝试在构建阶段中手动链接libCommon时,我得到了一堆重复的符号错误(让我相信它已经链接了?)。到底是什么?

With this setup, myApp owns all the pods, and then in the libCommon build settings I specify the path to the pod headers. This builds OK until I attempt to use one of the classes in libCommon. Once I do that, I get one of those _OBJC_CLASS_$_Blah errors (which tells me that although the headers are available, it's still not linked properly). When I try to manually link libCommon in "Build Phases" I get a bunch of duplicate symbol errors (which leaves me to believe it's already linked?). What the heck?

这样做的方法是什么,我的podfile应该是什么样的?

What's the way to do this properly and what should my podfile look like?

推荐答案

CocoaPods创建一个隐式根目标,默认情况下链接到项目的第一个目标。当您创建另一个目标并且子目标定义未继承link_with选项时,您的设置无效。为了生成link_with选项,您可以将其移动到MyApp目标定义的块内。

CocoaPods creates an implicit root target which by default links with the first target of the project. As you are creating another target and the link_with option is not inherited by children target definitions your set up is not working. In order to make the link_with option you can move it inside the block of the MyApp target definition.

当Common目标与Pod链接时,如果您将其链接到当应用程序与Common链接时,MyApp会导致重复的符号错误。在这种情况下,您只需要将标头提供给MyApp目标即可。这很简单,但目前还没有合适的DSL,所以暂时作为一个解决方案有点hacky(但支持)。

As the Common target links with the Pods, if you link those with the MyApp it will result in the duplicate symbols error as the app links with Common. In this case you just need to make the headers available to the MyApp target. This is simple to do but there isn't a proper DSL yet so for the moment is a bit hacky as a solution (but supported).

workspace 'MyApp.xcworkspace'
platform :ios, '5.0'

target 'Common' do
  pod 'AFNetworking',               '1.1.0'
  pod 'TTTAttributedLabel',         '1.6.0'
  pod 'JSONKit',                    '1.5pre'
  pod 'Reachability',               '3.1.0'

  target 'MyApp', :exclusive => true do
    xcodeproj 'MyApp.xcodeproj'
  end
end

这篇关于使用现有静态库和iOS应用程序配置Cocoapods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆