pod 库加子库的几个注意事项

文章讲述了在Podspec文件中管理子库时的两个关键点:一是子库可以依赖其他平级子库,例如TPWriteCommentAsk依赖TPTextView;二是子库简称不能以大写字母开头,错误示例会导致编译错误。另外,如果在示例工程中执行podinstall后找不到子库,可能是因为未在podspec文件中正确配置子库。
摘要由CSDN通过智能技术生成

1 一个子库是可以依赖另一个平级的子库的
我们给pod 库添加子库的时候,一个子库是可以依赖另一个子库的
如下

 s.subspec 'defaultView' do |defaultView|
    defaultView.source_files = 'commonComponent/Classes/defaultView/**/*'
    defaultView.public_header_files = 'commonComponent/Classes/defaultView/**/*.h'
    defaultView.dependency 'Masonry'
  end
  
  s.subspec 'TPHttpController' do |tpvc|
      tpvc.source_files = 'commonComponent/Classes/TPHttpController/**/*'
      tpvc.public_header_files = 'commonComponent/Classes/TPHttpController/**/*.h'
      tpvc.dependency 'commonComponent/defaultView'
      tpvc.dependency 'commonComponent/appConfig'
      tpvc.dependency 'commonComponent/BaseViewModel'
      tpvc.dependency 'remoteComponent', '0.0.3'
      tpvc.dependency 'lottie-ios', '2.5.3'
  end
  
  s.subspec 'appConfig' do |appConfig|
      appConfig.source_files = 'commonComponent/Classes/appConfig/**/*'
      appConfig.public_header_files = 'commonComponent/Classes/appConfig/**/*.h'
  end
  
  s.subspec 'TPTextView' do |tptextView|
      tptextView.source_files = 'commonComponent/Classes/TPTextView/**/*'
      tptextView.public_header_files = 'commonComponent/Classes/TPTextView/**/*.h'
  end
  
  s.subspec 'TPWriteCommentAsk' do |writecommentAsk|
      writecommentAsk.source_files = 'commonComponent/Classes/TPWriteCommentAsk/**/*'
      writecommentAsk.public_header_files = 'commonComponent/Classes/TPWriteCommentAsk/**/*.h'
      writecommentAsk.dependency 'remoteComponent', '0.0.3'
      writecommentAsk.dependency 'commonComponent/TPTextView'
      writecommentAsk.dependency 'Masonry'
  end
  

其中 子库 TPWriteCommentAsk 就依赖于同级的 TPTextView 库,注意,依赖同级子库的时候,
使用的是原名,而不是简称

请添加图片描述在这里插入图片描述

2 子库的的简称不能以大写字母开头

[!] Invalid commonComponent.podspec file: formal argument cannot be a constant
…pec ‘TPTextView’ do |TPTextView|

在这里插入图片描述

Podspec 文件中的 代码

  s.subspec 'TPTextView' do |TPtextView|
      tptextView.source_files = 'commonComponent/Classes/TPTextView/**/*'
      tptextView.public_header_files = 'commonComponent/Classes/TPTextView/**/*.h'
  end

错误原因, 使用了大些字母开头,

正确的写法

 s.subspec 'TPTextView' do |tptextView|
      tptextView.source_files = 'commonComponent/Classes/TPTextView/**/*'
      tptextView.public_header_files = 'commonComponent/Classes/TPTextView/**/*.h'
  end
  

3 添加子库文件之后,在示例工程中执行pod install, 找不到子库
如图

实际文件夹中已经添加了子库文件
请添加图片描述

但是执行pod install 之后,在工程目录中看不到添加的子库文件
请添加图片描述

其原因就是,我们没有在podspec 描述文件中添加子库的配置
如图
请添加图片描述

添加过就好了
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值