IOS 私有组件创建

准备

  • 一份项目的git仓库,并把项目clone到本地
  • 一个空仓库(用来保存pod源)

1.创建podspec文件(xxxx.podspec)

  • podspec文件为pod源的描述文件,创建步骤为
cd 到你的项目文件夹下
pod spec create podName   //podName 为你的pod源名
  • 编辑.podspec文件
#pod name
  s.name         = "ss"
#pod 版本号
  s.version      = "0.0.1"
#pod 描述
  s.summary      = "缓存基础组件"
  s.description  = "this is very good 请求基础组件"
#pod 主页
  s.homepage     = "http://www.baidu.com"
#pod 开源协议 --这里检查一下你的项目文件夹下是否有 LICENSE 文件,如果没有需要自己创建(这个必须创建)。
  s.license          = { :type => "MIT", :file => "LICENSE" }
  s.author             = { "admin" => "****" }
#pod 最低支持IOS 版本
  s.platform     = :ios, "9.0"
#pod { :git => 你的项目远端git地址, :tag => "v#{s.version}"}
  s.source       = { :git => "ssh://admin@117.139.163.26:29418/cheku/dev/ios/CKStore.git", :tag => "v#{s.version}"}
#pod源会拉取你的远端git仓库中,Store 文件夹下的内容。
#格式为 s.source_files  = "Classes","Classes/**/*"   //Classes为你的文件夹名,通过这个路径去查找代码
  s.source_files  = "Store","Store/**/*"
#这里为你的pod源 引用的一些资源文件路径,如图片资源
#  s.resource      = "SDPickerController/Resources/Mytools.bundle"
  s.exclude_files = "Classes/Exclude"
  s.requires_arc=true

2.为pod源 添加地址

  • 这里的地址为,你在准备过程中,创建的一个空仓库(用来存放pod源)
格式为 pod repo add 源名 源地址
pod repo add requestPod ssh://admin@117.139.163.26:29418/cheku/dev/ios/requestPod.git

3.添加tag

  • 为远端git仓库代码添加tag(这里的git仓库为你的项目地址仓库) :pod会根据的你xxx.podspec文件去你的远端仓库拉取代码。
#git tag 版本号
git tag "v0.0.1"
#push 远端
git push --tags

//其他操作
//查看当前所有   pod repo。。
//删除一个pod源    pod repo remove storepod-1     :storepod-1  为你的podName

4.push 到pod源

#pod repo push pod源名 pod源文件
pod repo push requestPod request.podspec
//在push 之前可以用pod lib lint ****.podspec 来检查podspec文件是否正确

5. 项目中podfile 中添加pod引用

例:

platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!

# 公有仓库
source 'https://github.com/CocoaPods/Specs.git'

# 私有仓库--你的私有pod源地址
source 'ssh://admin@117.139.163.26:29418/cheku/dev/ios/requestPod.git'
source 'ssh://admin@117.139.163.26:29418/cheku/dev/ios/storePod.git'    

target 'CheKu' do
    
    
    # 私有pod
    pod 'request'
    pod 'ss'
    
    #object-c module
    pod 'AFNetworking', '~> 3.2.0'
    pod 'SDWebImage', '~> 4.3.2'
end

常见问题

[!] /usr/bin/git clone ssh://admin@117.139.163.26:29418/cheku/dev/ios/CKRequest.git requestPod

fatal: destination path 'requestPod' already exists and is not an empty directory.
  • 为pod添加pod仓库失败,检查pod源仓库,初次添加,这个仓库应该为空仓库
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/IOSzhangwei/requestPod.git /var/folders/5w/_sq_vf_10fdcxxkt3c9wnh1m0000gn/T/d20180409-2905-zmvvxq --template= --single-branch --depth 1 --branch 0.0.7

Cloning into '/var/folders/5w/_sq_vf_10fdcxxkt3c9wnh1m0000gn/T/d20180409-2905-zmvvxq'...
warning: Could not find remote branch 0.0.7 to clone.
fatal: Remote branch 0.0.7 not found in upstream origin
  • pod在去拉取git代码的时候没有发现0.0.7的版本号,检查远端git是否有该版本号,检查xxx.podspec中的s.version 是否错误。
Password: t
 -> request (0.0.8)
    - WARN  | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
    - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

[!] The `request.podspec` specification does not validate.
  • 检查source_files 语法错误
 -> SEShowTips (0.0.1)
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - WARN  | xcodebuild:  MBProgressHUD/MBProgressHUD.h:88:45: warning: this block declaration is not a prototype [-Wstrict-prototypes]
    - WARN  | xcodebuild:  MBProgressHUD/MBProgressHUD.m:401:106: warning: this block declaration is not a prototype [-Wstrict-prototypes]
    - ERROR | xcodebuild:  /Users/zhangWei/Desktop/ComponentShowTips/SEShowTips/UIView+SETips.m:10:9: error: 'MBProgressHUD.h' file not found with <angled> include; use "quotes" instead
  • 里边包含2了个 error 和warn,发生原因为为,我在自己的私有pod,引用了MBProgressHUD 三方库。
    *查看了git 上MBProgressHUD 的podspec 文件,发现他引用了2个包,在我自己的podspec也添加s.frameworks = "CoreGraphics", "QuartzCore" ,引用。
    *通过--use-libraries 增加编译 和 --allow-warnings 忽略警告,直接进行强制push
    *pod repo push SEShowTips SEShowTips.podspec --use-libraries --allow-warnings

参考文档

https://www.jianshu.com/p/67a6004f6930
https://www.jianshu.com/p/d7d1942dd3f1

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容