x土匪

导航

CocoaPods创建私有pods

由于项目需求,需要把项目的不同模块拆分出来即 组件化 ,一开始想做成多target模式,后来换成私有pods

CocoaPods的安装和使用,网上很多,自行搜索即可。

听说可以基于svn创建pod私有库文章点这里),但我断断续续的折腾了两三天没成功,实在不想搞了,只能老老实实搞git的。有谁弄成功了希望不吝赐教。

 

cd到需要做库的工程目录下 创建一个podspec文件
pod spec create podName (如:pod spec create testPods,会在当前目录生成 testPods.podspec)
修改testPods.podspec文件,修改.podspec文件时可参考这里
可以用vim修改 也可以使用文本编译器进行修改,(注意:使用文本编辑器修改时注意标点符号,要保证的半角符号,文本编辑器有时会自动改成全角的)

在使用时需要注意的是:Podfile文件里面的写法区别于公有库  示例:pod 'Utility',:git=>"http://xxxxx.git"(替换为真实的git地址)

 

更具体的请参考:http://www.cnblogs.com/superhappy/p/3468377.html

        http://www.cocoachina.com/ios/20150228/11206.html

我遇到了这个错误:Unable to run command 'StripNIB AQPhotoPickerView.nib' - this target might include its own product

是因为我指定的文件夹里有xib文件,xib文件算是资源文件的,需要另外添加s.resource引入

修正前

  s.source_files = "pod/classes/**/*"

修正后

s.source_files  = "pod/classes/**/*.{h,m}"
s.resource = "pod/classes/TestViewController.xib"

2016-07-14 更新

如何在私有库里引用私有库(基于CocoaPods v1.0.0)

  一般,在组件化之路上,不可避免的会用到 私有库中引用私有库,即 s.dependency "私有库"。网上的资料我没有找到完整的、可行的流程,我断断续续的折腾了3、4天才终于解决了这个问题,特来次记录下:

1、首先要简单说下pod install 的流程

  终端运行 pod install后,会默认从github上搜索公开库的,因此,我们需要在PodFile上指明我们的私有库的地址,在PodFile 的顶上添加如下代码:

  source 'https://github.com/CocoaPods/Specs.git' # 这个是github上公有库的地址,没有这个,pod就不会去公有库查询,就不能下载公有库的东西

  source '私有库地址',可以放多个source

2、前面的步骤基本一致:

  1)创建远程仓库

  2)创建并编辑 .podspec 文件

  3)pod repo add #repo名# #远程仓库地址,如:http://git.xxxxx/xx/test.git#

  4)验证 pod lib lint

3、验证通过

  pod spec lint --sources='http://git.#私有仓库地址#,https://github.com/CocoaPods/Specs'

  核心就在这了,不然会报找不到repo的错误。

 

4、打tag

  cd到项目文件夹  

      $ git tag #版本号# 

      $ git push --tags

5、推送到远端仓库(记住:在推送之前要先打tag,不然会出错)

  pod repo push #本地Repo名字# #.podspec名#   如:pod repo push test test.podspec

  打开远端仓库,会看到刚才打的tag

6、私有库更新后,要重复4、5步

 

2016-09-09 更新

 这里需要补充说明一点,

  私有库有引用私有库的情况,在验证已经推送podspec的时候都需要加上所有的资源地址,不然,pod会默认从cocoapods官方查询的。

  如,私有库a要引用私有库b,在验证与推送私有库a的时候,要加上私有库b的远程仓库地址,如下

  注意:要在pod lib lint 或者 pod spec lint 以及 pod repo push ....时候加上被引用的私有库地址  

 pod spec lint --sources='#私有库b的远程仓库地址(如:http://xxxxxx.git)#,https://github.com/CocoaPods/Specs'
 pod repo push #本地Repo名字# #.podspec名# --sources='[私有库b的远程仓库地址(如:http://xxxxxx.git)],https://github.com/CocoaPods/Specs'

#demo:
 pod spec lint --sources='http://xxxxxx/iOSRepos.git,https://github.com/CocoaPods/Specs'

 pod repo push iOSTest iOSTest.podspec --sources='http://git.yinqiyun.com/xfx/iOSRepos.git,https://github.com/CocoaPods/Specs'

 

  有多少个私有库就加多少个地址,用 半角“,”隔开

 

2016-07-15 更新

统一管理私有库版本

  前面我们拆分了一堆组件,地址都是独立的太过分散不好管理,因此需要建立一个统一的repo来管理这些组件。

  1、在远端创建私有repo,如:http://git.xxxx.com/xfx/iOSRepo.git

  2、添加私有repo到CocoaPods

    套用原文:      

$ pod repo add REPO_NAME SOURCE_URL
注意:在你创建本地pods库的时候,需要检查你推送到源地址的权限。

你可以使用下面两条指令去检查你的安装是否完成:

$ cd ~/.cocoapods/repos/REPO_NAME
$ pod repo lint .

    如:pod repo add iOSRepo  http://git.xxxx.com/xfx/iOSRepo.git

    注:我在用 pod repolint 检查时,会在后面无限打出 .......... 字符,不知啥原因,不过没有影响。

  3、添加组件的 .podspec到刚创建的repo

    这一步参考前面2016-07-14更新的 5、推送到远端仓库,不过repo名要改成刚才创建的repo名,即 iOSRepo

  详情请参考这里。

  

2016-09-12 更新

  报错 ··· error: include of non-modular header inside framework module ··· [-Werror,-Wnon-modular-include-in-framework-module]

  解决办法:在pod lib lint 或者 pod spec lint 以及 pod repo push ....时候加上   --use-libraries

    pod lib lint --use-libraries
    #或者
    pod spec lint --use-libraries

    #当然,在提交的时候也要加上
    pod repo push <repoName> <podspec> --use-libraries

   参考:http://stackoverflow.com/questions/29132496/cocoapod-spec-wont-lint-with-0-36

 

2016-09-22 更新

  引用自己的或者第三方的framework或者.a静态库

  加上以下代码即可:

  s.ios.vendored_frameworks = "xxx/**/*.framework"
  s.ios.vendored_libraries = "xxx/**/*.a"

 

 

 

仅记录。

 

参考:

1、http://www.cnblogs.com/superhappy/p/3468377.html

2、http://www.cocoachina.com/ios/20150228/11206.html

3、http://www.jianshu.com/p/ddc2490bff9f/comments/3113292#comment-3113292

4、http://blog.csdn.net/andanlan/article/details/51713595

posted on 2016-07-08 18:12  Darrick  阅读(9526)  评论(0编辑  收藏  举报