ios – 为具有多个目标和不同平台的项目编写Podfile

前端之家收集整理的这篇文章主要介绍了ios – 为具有多个目标和不同平台的项目编写Podfile前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在准备一个支持OS X和iOS的pod.我的pod有一些自己的依赖关系,它们在podspec文件中定义,所以我使用Podfile来管理我用来开发pod并运行测试的项目的依赖关系.我正在使用 CocoaPods 0.33.1.

我有四个目标:

> MFDynamic.iOS(iOS静态库)
> MFDynamic.iOS.Tests(iOS测试包)
> MFDynamic.Mac(Mac框架)
> MFDynamic.Mac.Tests(Mac测试包)

我想要的行为是这样的:

>指定每个目标的平台(因为有iOS和OS X目标).
>将podspec依赖项包含为非测试目标中的pod.
>只能将Kiwi / XCTest指定为依赖关系.

但是,无论如何,我无法编写一个可以工作的Podfile.运行pod安装不会将CocoaPods的构建阶段添加到我的目标,也不会将相应的xcconfig文件添加到项目中. CocoaPods不会在Podfile中输出任何错误信息.

这是我最近失败的尝试:

target 'MFDynamic.iOS' do
  platform :ios,'6.1'
  podspec :path => '../MFDynamic.podspec'
end

target 'MFDynamic.Mac' do
  platform :osx,'10.7'
  podspec :path => '../MFDynamic.podspec'
end

target 'MFDynamic.iOS.Tests' do
  platform :ios,'6.1'
  pod 'Kiwi/XCTest','~> 2.2.4'
end

target 'MFDynamic.Mac.Tests' do
  platform :osx,'10.7'
  pod 'Kiwi/XCTest','~> 2.2.4'
end

简化一点产生相同的结果(即在项目中没有集成):

target 'MFDynamic.iOS' do
  platform :ios,'6.1'
  pod 'AFNetworking','~> 2.2'
end

target 'MFDynamic.Mac' do
  platform :osx,'10.7'
  pod 'AFNetworking','~> 2.2'
end

我甚至会考虑将所有pod连接到所有目标,最后当项目通过CocoaPods包含在别人的工作中时,它只会获取相应的源文件.所以即使说,Kiwi与iOS静态库目标相关联,与CocoaPods集成时也不会被拖入用户的项目.我真的很想避免这种做法,但如果这是唯一的办法

无论如何,以这种心态我已经尝试了以下,没有多少运气:

link_with 'MFDynamic.iOS','MFDynamic.Mac','MFDynamic.iOS.Tests','MFDynamic.Mac.Tests'

podspec :path => '../MFDynamic.podspec'
pod 'Kiwi','~> 2.2'

在这种情况下,我收到一个pod安装错误

NoMethodError - undefined method `include?' for nil:NilClass
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/xcodeproj-0.17.0/lib/xcodeproj/project/object/native_target.rb:95:in `platform_name'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:471:in `block in compute_platform_for_target_definition'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:469:in `each'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:469:in `compute_platform_for_target_definition'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:519:in `block in compute_target_platforms'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:514:in `each'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:514:in `compute_target_platforms'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:55:in `analyze'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:176:in `analyze'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:98:in `block in resolve_dependencies'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/user_interface.rb:52:in `section'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:97:in `resolve_dependencies'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:89:in `install!'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command/project.rb:40:in `run_install_with_update'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command/project.rb:70:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/claide-0.6.1/lib/claide/command.rb:281:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command.rb:48:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/bin/pod:33:in `<top (required)>'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/pod:23:in `load'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/pod:23:in `<main>'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `eval'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `<main>'

我的问题:

要做什么正确的方法(见上文)?如何让CocoaPods成功整合到我的项目和iOS / Mac目标?我已经阅读了Podfile文档,但发现它在这方面缺乏.

解决方法

得到它了!这并不是因为我以为使用Podfile语法造成的.

相反,这是因为我手动清理了所有CocoaPods相关内容的构建阶段,以执行干净的pod安装(不要问为什么).

在看了一下CocoaPods source code之后,我注意到,当pods静态库存在于目标的“Link Binary With Libraries”构建阶段时,跳过了对目标的集成.哎呦!

从我的每个目标和运行的pod安装中删除libPods-xxxx.a文件,再次执行了我的目标集成.

猜你在找的iOS相关文章