IOS 私有組件創(chuàng)建

準(zhǔn)備

  • 一份項目的git倉庫,并把項目clone到本地
  • 一個空倉庫(用來保存pod源)

1.創(chuàng)建podspec文件(xxxx.podspec)

  • podspec文件為pod源的描述文件,創(chuàng)建步驟為
cd 到你的項目文件夾下
pod spec create podName   //podName 為你的pod源名
  • 編輯.podspec文件
#pod name
  s.name         = "ss"
#pod 版本號
  s.version      = "0.0.1"
#pod 描述
  s.summary      = "緩存基礎(chǔ)組件"
  s.description  = "this is very good 請求基礎(chǔ)組件"
#pod 主頁
  s.homepage     = "http://www.baidu.com"
#pod 開源協(xié)議 --這里檢查一下你的項目文件夾下是否有 LICENSE 文件,如果沒有需要自己創(chuàng)建(這個必須創(chuàng)建)。
  s.license          = { :type => "MIT", :file => "LICENSE" }
  s.author             = { "admin" => "****" }
#pod 最低支持IOS 版本
  s.platform     = :ios, "9.0"
#pod { :git => 你的項目遠(yuǎn)端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源會拉取你的遠(yuǎn)端git倉庫中,Store 文件夾下的內(nèi)容。
#格式為 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源 添加地址

  • 這里的地址為,你在準(zhǔn)備過程中,創(chuàng)建的一個空倉庫(用來存放pod源)
格式為 pod repo add 源名 源地址
pod repo add requestPod ssh://admin@117.139.163.26:29418/cheku/dev/ios/requestPod.git

3.添加tag

  • 為遠(yuǎn)端git倉庫代碼添加tag(這里的git倉庫為你的項目地址倉庫) :pod會根據(jù)的你xxx.podspec文件去你的遠(yuǎn)端倉庫拉取代碼。
#git tag 版本號
git tag "v0.0.1"
#push 遠(yuǎn)端
git push --tags

//其他操作
//查看當(dāng)前所有   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源倉庫,初次添加,這個倉庫應(yīng)該為空倉庫
    - 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代碼的時候沒有發(fā)現(xiàn)0.0.7的版本號,檢查遠(yuǎn)端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,發(fā)生原因為為,我在自己的私有pod,引用了MBProgressHUD 三方庫。
    *查看了git 上MBProgressHUD 的podspec 文件,發(fā)現(xiàn)他引用了2個包,在我自己的podspec也添加s.frameworks = "CoreGraphics", "QuartzCore" ,引用。
    *通過--use-libraries 增加編譯 和 --allow-warnings 忽略警告,直接進(jìn)行強制push
    *pod repo push SEShowTips SEShowTips.podspec --use-libraries --allow-warnings

參考文檔

http://www.itdecent.cn/p/67a6004f6930
http://www.itdecent.cn/p/d7d1942dd3f1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容