利用cocoapods管理開源項目,支持 pod install安裝整個流程記錄(github公有庫)

利用cocoapods管理開源項目,支持 pod install安裝整個流程記錄(github公有庫),完成預期的任務,大體有下面幾步:javascript

1.代碼提交到github平臺html

2.建立.podspecjava

3.編輯.podspecios

4.添加taggit

5.驗證github

6.註冊CocoaPodsjson

7.發佈swift

詳細流程以下:

1.代碼提交到github平臺

將本身的代碼上傳到github上面(不是惟一的,上傳到任何平臺上均可以,前提是項目是開源的)。至於怎麼利用github管理咱們的項目,能夠參考:http://www.cnblogs.com/richard-youth/p/4684100.html

2.建立.podspec

首先要利用cocoapods將項目管理起來,具體能夠參考:http://www.cnblogs.com/richard-youth/p/4508049.html
而後cd到你項目的目錄,執行命令( yooweiTest這個是你框架的名稱)
$ pod spec create yooweiTest

3.編輯.podspec

建立好後打開,刪除註釋, 前面有#的爲註釋,若是你想知道每一個東西的含義能夠了解一下

整理以後的文件
yooweiTestyooweiTesthttps://github.com/yoowei/yooweiTest     s.license= { :type => "MIT", :file => "LICENSE" }
https://github.com/yoowei/yooweiTest.git.git結尾。
s.source_files  = "yooweitest", "yooweitest/**/*" //須要和.podspec 的名稱同樣??Pod::Spec.new do |s| s.name = ""
s.version = "1.0"
s.ios.deployment_target = '7.0'
s.summary = ""
s.homepage = "
"
s.author = { "yoowei" => "yoowei@126.com" }
s.source = { :git => "
", :tag => s.version } /注意須要
接下來說解一下每行代碼的含義
s.name:名稱,pod search 搜索的關鍵詞,注意這裏必定要和.podspec的名稱同樣,不然報錯
s.version:版本號
s.ios.deployment_target:支持的pod最低版本
s.summary: 簡介
s.homepage:項目主頁地址
s.license:許可證
s.author:做者
s.social_media_url:社交網址
s.source:項目的地址
s.source_files:須要包含的源文件
s.resources: 資源文件
s.requires_arc: 是否支持ARC
s.dependency:依賴庫,不能依賴未發佈的庫
s.dependency:依賴庫,若有多個能夠這樣寫
s.license= { :type => "MIT", :file => "LICENSE" }
這裏建議你們這樣寫,若是寫別的會報警告,致使後面一直提交失敗
  • source_files:寫法及含義建議你們寫第一種或者第二種
    "yooweitest/* "yooweitest/yoowei/*.{h,m}" "yooweitest/**/*.h"
  • 「*」 表示匹配全部文件
  • 「*.{h,m}」 表示匹配全部以.h和.m結尾的文件
  • 「**」 表示匹配全部子目錄
  • s.source 常見寫法
    s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :commit => "68defea" } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => 1.0.0 } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => s.version }
  • commit => "68defea" 表示將這個Pod版本與Git倉庫中某個commit綁定
  • tag => 1.0.0 表示將這個Pod版本與Git倉庫中某個版本的comit綁定
  • tag => s.version 表示將這個Pod版本與Git倉庫中相同版本的comit綁定
另外:
一、引用靜態庫: 「(.ios).library」。去掉頭尾的lib,用「,」分割 。注意: (.ios)括號括起來表明能夠省略
// 引用libxml2.lib和libz.lib.   
spec.libraries = 'xml2', 'z'
二、引用公有framework:"(.ios).framework" 用」,」分割. 去掉尾部的」.framework」
spec.frameworks = 'UIKit','SystemConfiguration', 'Accelerate'
三、引用本身生成的framework:’(.ios).vendored_frameworks’  用」,」分割 路徑寫從.podspec所在目錄爲根目錄的相對路徑 ps:這個不要省略.framework spec.ios.vendored_frameworks = 'Pod/Assets/*.framework'
四、引用本身生成的.a文件, 添加到Pod/Assets文件夾裏. Demo的Example文件夾裏也須要添加一下, 否則找不到
spec.ios.vendored_libraries = 'Pod/Assets/*.a'
注意:在提交到私有倉庫的時候須要加上--use-libraries 

4.建立LICENSE(許可證/受權)文件,此文件必需要有

建立一個文件名字命名爲LICENSE,內容爲:只須要把前面的版權改一下就好了,後面的都同樣。

MIT LicenseCopyright (c) 2017Permission is hereby granted, free of charge, to any person obtaining a copyvim

of this software and associated documentation files (the "Software"), to dealxcode

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

可是:通常咱們建立倉庫的時候,大多數已經建立好了的。

5.上傳到Git

將包含配置好的 .podspec, LICENSE 的項目提交 Git倉庫

6.打tag

$ git tag
1.0
$ git tag -a 2.0 -m "2.0版本"
$ git tag
1.0
2.0
$ git push origin 2.0
Counting objects:
1, done.Writing objects: 100% (1/1), 173 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)To https://github.com/yoowei/yooweiTest.git 
* [new tag]         2.0 -> 2.0
由於cocoapods是依賴tag版本的,因此必須打tag。之後再次更新只須要把你的項目打一個tag,而後修改.podspec文件中的版本,接着提交到cocoapods官方就能夠了。
注意將tag提交這一步很重要

7.驗證.podspec文件

到此檢查一下你工程下面的文件, 你的項目, .podspec文件, LICENSE文件是否存在。驗證會先測試本地 .podspec 文件是否存在語法錯誤.
// --verbose 若是驗證失敗會報錯誤信息
$ pod spec lint yooweiTest.podspec --verbose
說明:2017.1.14 我將mac電腦系統升級到最新,所須要的cocoapods等環境從新更新安裝,包括該項目再github上面的項目倉庫也是從新創建的(通過修改),此次驗證竟然一次性經過,沒有出現任何問題。
 yooweiTest.podspec passed validation.

前段時間操做遇到的錯誤和警告:

一、

-> yooweiTest (1.0)
    - WARN  | github_sources: Github repositories should end in `.git`. //注意須要以.git結尾
    - WARN  | description: The description is equal to the summary.
    - NOTE  | xcodebuild:  warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript for architecture i386
    - NOTE  | xcodebuild:  warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript for architecture x86_64

Analyzed 1 podspec.
[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
    `echo "2.3" > .swift-version`.
$ pod lib lint --allow-warnings

$ echo "2.3" > .swift-version

二、 -> JSPatchtest (1.0.0)

    - ERROR | name: The name of the spec should match the name of the file.// 這個是要保證.podspe文件的名稱和裏面s.name保持一致

    - WARN  | github_sources: Github repositories should end in `.git`.

    - WARN  | description: The description is equal to the summary.

    - ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `JSPatchtest` in `/Users/galahad/Desktop/yooweiTest`) during validation.

[!] JSPatchtest did not pass validation, due to 2 errors and 2 warnings.

3  、

[!] Error installing JSPatchtest
 -> yooweitest (1.0.0)
    - WARN  | description: The description is shorter than the summary.
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yoowei/yooweiTest.git /var/folders/rg/gmjp61bx0x95t4tjx2hh_3sr0000gn/T/d20170113-4028-cvivmq --template= --single-branch --depth 1 --branch 1.0.0

[!] The spec did not pass validation, due to 1 error and 1 warning.

解決方法:執行 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer (-switch 後面加上你的Xcode.app包內容裏的Developer的文件夾路徑便可).

驗證成功後:

yooweiTest passed validation.

驗證失敗:

[!] The spec did not pass validation, due to 1 error.

若是出現錯誤,就各式各樣,根據描述進行解決就能夠了。

8.註冊Trunk

若是要添加到Cocoapods的官方庫了,可使用trunk工具,具體能夠查看官方文檔。若是是私有庫的話,詳見:http://www.cnblogs.com/richard-youth/p/6289015.html
trunk須要CocoaPods 0.33版本以上,用pod --version 命令查看版本,若是CocoaPods版本低,須要升級。已經註冊過的不須要註冊,怎麼看本身有沒有註冊
$ pod trunk me
- Name:     yoowei 
- Email:    yoowei@126.com 
- Since:    January 12th, 04:38 
- Pods:     None 
- Sessions:    - January 12th, 04:38 - May 21st, 03:35. IP: 218.205.57.27
若是沒有註冊的話  [!] You need to register a session first.註冊
// 加上--verbose能夠輸出詳細debug信息,方便出錯時查看。
$ pod trunk register yoowei@126.com "yoowei" --verbose
[!] Please verify the session by clicking the link in the verification email that has been sent to yoowei@126.com
註冊完成以後會給你的郵箱發個郵件,進入郵箱郵件裏面有個連接,須要點擊確認一下。

補充: 
$ pod trunk help 能夠查詢通常的命令
那麼怎麼將本身刪除????
其實咱們能夠連根拔起,
# 顯示隱藏文件
defaults write com.apple.finder AppleShowAllFiles Yes && killall Finder
# 不顯示隱藏文件
defaults write com.apple.finder AppleShowAllFiles No && killall Finder

咱們顯示隱藏文件後,在用戶目錄下,找到 /Users/galahad/.rvm 

直接將隱藏文件.rvm刪除
$ pod trunk me
-bash: /Users/galahad/.rvm/gems/ruby-2.2.2/bin/pod: No such file or directory
一切OK🌶

9.發佈

發佈時會驗證 Pod 的有效性,若是你在上面步驟中手動驗證 Pod 時使用了 --use-libraries 或 --allow-warnings 等修飾符,那麼發佈的時候也應該使用相同的字段修飾,不然出現相同的報錯。
--allow-warningspod trunk push yooweiTest.podspec 
成功了之後會出現如下內容

這個時候,再用
$ pod trunk me 
- Name:     yoowei 
- Email:     yoowei@126.com 
- Since:     January 12th, 04:38 
- Pods:    - yooweiTest 
- Sessions:    - January 12th, 04:38 - May 22nd, 00:54. IP: 218.205.37.37
你會發現- Pods:    - yooweiTest 已經有了內容了。
 
10.驗證
當即搜索
$ pod search yooweiTest
[!] Unable to find a pod with name, author, summary, or description matching `yooweiTest`
沒有搜到......
本身摸索着......進行如下嘗試
首先:
$ pod setup
而後:
 

$ pod search yoowei

[!] Unable to find a pod with name, author, summary, or description matching `yoowei`

仍是失敗......
因爲 pod setup成功後會生成~/Library/Caches/CocoaPods/search_index.json文件。

終端輸入rm ~/Library/Caches/CocoaPods/search_index.json

刪除成功後再執行pod search 一切OK🌶

$ rm ~/Library/Caches/CocoaPods/search_index.json

$ pod search yoowei

Creating search index for spec repo 'master'.. Done!

$ pod search yoowei

-> yooweiTest (1.0)

   yooweiTest just test.

   pod 'yooweiTest', '~> 1.0'

   - Homepage: https://github.com/yoowei/yooweiTest

   - Source:   https://github.com/yoowei/yooweiTest.git

   - Versions: 1.0 [master repo]

 
補充:Claim your Pod 聲稱,索取: https://trunk.cocoapods.org/claims/new 
能夠利用 pod trunk info yooweiTest 查詢相關信息
$ pod trunk info yooweiTest
yooweiTest   
- Versions:      - 1.0 (2017-01-14 06:50:53 UTC)   
- Owners:      - yoowei <yoowei@126.com> 
點擊SEND進入頁面後: $ pod trunk help 能夠查詢通常的命令,包括添加開發者
我的理解:最後無論你是否是有爭議,他們要求你說明爲何來到這裏,我以爲你想寫就寫,不寫拉倒。 若有不對,歡迎交流。
相關文章
相關標籤/搜索