利用Cocoapods建立基於SVN的私有庫podspec

因爲項目年後要進行組件化,考慮到公司內部實現的一些私有組件,不對外公開,而又想在不一樣項目中使用,該怎麼辦呢?因爲cocoapods有了強大的功能,能夠本身建立podspec,更能夠設置私有的庫。那麼利用cocoapods來管理公共組件就很方便了。css

使用Cocoapods製做私有庫就完美的解決了這個問題。下圖就是使用私有庫帶給咱們的好處:ios

 

Cocoapods是如何實現查找第三方庫呢?以下圖:git

 

從圖中,能夠看到經過.podspec能夠找到咱們想要的第三方庫,那麼.spec是什麼呢?以下:面試

Pod::Spec.new do |s|服務器

s.name         = "JSPatchtest"svn

s.version      = "0.0.1"組件化

s.summary      = "yoowei 測試利用SVN建立私用庫"測試

s.description  = <<-DESCurl

yoowei 測試利用SVN建立私用庫spa

DESC

s.homepage     = "https://www.baidu.com"

s.license      = "MIT"

s.author             = { "yoowei" => "yoowei@126.com" }

s.platform     = :ios, "7.0"

s.source       = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest",:tag => "0.0.1"}

s.source_files  = 'yoowei/**/*'

end

至此,咱們明白了查找到第三方庫背後的原理。可是,具體如何進行搜索的呢?

先解釋一個概念,什麼是Spec Repo?它是全部的Pods的一個索引,也就是一個容器(集合),全部公開的Pods都在這個裏面。實際上就是一個Git倉庫remote端,當你使用了Cocoapods,這個倉庫會被clone到本地的~/.cocoapods/repos目錄下,進入到這個文件下能夠看到master文件夾,就是官方的Spec Repo了。當你pod search的時候就在master這個文件下面查找的。

 

如何製做出屬於本身的私有庫?

可是問題來了,咱們公司用的是SVN ,網上的資料介紹的絕大多數是基於git的 ,怎麼辦?

查找資料發現:

  #  Specify the location from where the source should be retrieved.

  #  Supports git, hg, bzr, svn and HTTP.

 結果是明確的,支持SVN製做私有庫,那麼接下來就是不斷的踩坑,終於成功了,記錄下來備忘,若是可以幫到別人更好。

 至於須要SVN帳號密碼,在接下來的步驟裏面會有設計。

一、我利用JSPatch做爲本身的私有庫的組件,進項測試,創建以下的目錄結構,並提早將JSPatchtest上傳到咱們SVN服務器

SVN上面的文件結構(以下)

二、把svn上面對應的JSPatchtest代碼check out到本地,cd到JSPatchtest該目錄下,使用pod命令建立一個podspec文件。

$ pod spec create JSPatchtest

具體終端操做以下:

$ cd /Users/galahad/Desktop/yoowei 

$ svn co https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest

 

A    JSPatchtest/yoowei

A    JSPatchtest/yoowei/JPEngine.h

A    JSPatchtest/yoowei/JSPatch.js

A    JSPatchtest/yoowei/JPEngine.m

Checked out revision 41541.

$ cd /Users/galahad/Desktop/yoowei/JSPatchtest 

$ pod spec create JSPatchtest

 Specification created at JSPatchtest.podspec 

 

三、打開JSPatchtest.podspec文件,進行修改(不明白的能夠先查資料瞭解)。而後將文件提交到SVN服務器

Pod::Spec.new do |s|

s.name         = "JSPatchtest"

s.version      = "0.0.1"

s.summary      = "yoowei 測試利用SVN建立私用庫"

s.description  = <<-DESC

yoowei 測試利用SVN建立私用庫

DESC

s.homepage     = "https://www.baidu.com"

s.license      = "MIT"

s.author             = { "yoowei" => "yoowei@126.com" }

s.platform     = :ios, "7.0"

s.source       = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}

s.source_files  = 'yoowei/**/*'

end

當咱們用的svn時候,

s.source       = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}

細心的你應該發現默認的時候是有一個tags存在的,如今先刪掉,後面會敘述。

s.source_files  = "yoowei", "yoowei/**/*"

四、使用

剛巧下載了一個LXMySelf的demo,就在這裏面試一下

podfile文件描述以下:

target 'LXMySelf' do

pod 'AFNetworking'

pod 'Masonry'

pod 'UITableView+FDTemplateLayoutCell'

pod 'MJRefresh'

pod 'MJExtension'

pod 'MBProgressHUD'

pod 'SDWebImage'

pod 'YYCache'

pod 'SDCycleScrollView'

pod 'JSPatchtest', :svn => 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest'

end

注意若是是首次的話,會讓你輸入SVN權限密碼的。(因爲剛操做了一遍了,密碼已經輸入過了)

$ cd /Users/galahad/Desktop/yoowei/LXSelfProject-master 

$ pod install

Analyzing dependencies

Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`

Downloading dependencies

Using AFNetworking (3.1.0)

Installing JSPatchtest 0.0.1 (was 0.0.1)

Using MBProgressHUD (1.0.0)

Using MJExtension (3.0.13)

Using MJRefresh (3.1.12)

Using Masonry (1.0.1)

Using SDCycleScrollView (1.65)

Using SDWebImage (3.8.1)

Using UITableView+FDTemplateLayoutCell (1.4)

Using YYCache (1.0.3)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There are 10 dependencies from the Podfile and 10 total pods installed.

檢查一下,安裝成功。

五、補充tag設置

設置tag其實仍是很簡單的,我這裏使用的是cornrstone管理svn代碼。須要在JSPatchtest目錄下新建一個tags文件夾,我採用的是本地建立好,而後上傳到SVN。

 

SVN目錄結構以下,選中yoowei文件夾右擊 Tag ,填寫tag和選擇tags的位置,以後建立tags.

建立完tags以後的SVN目錄結構。

 

 六、再試

podfile文件描述以下:

target 'LXMySelf' do

pod 'AFNetworking'

pod 'Masonry'

pod 'UITableView+FDTemplateLayoutCell'

pod 'MJRefresh'

pod 'MJExtension'

pod 'MBProgressHUD'

pod 'SDWebImage'

pod 'YYCache'

pod 'SDCycleScrollView'

pod 'JSPatchtest', :svn => 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest',:tag =>'0.0.1'

end

終端操做:

$ pod install

Analyzing dependencies

Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`, tag `0.0.1`

Downloading dependencies

Using AFNetworking (3.1.0)

Installing JSPatchtest 0.0.1 (was 0.0.1)

Using MBProgressHUD (1.0.0)

Using MJExtension (3.0.13)

Using MJRefresh (3.1.12)

Using Masonry (1.0.1)

Using SDCycleScrollView (1.65)

Using SDWebImage (3.8.1)

Using UITableView+FDTemplateLayoutCell (1.4)

Using YYCache (1.0.3)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There are 10 dependencies from the Podfile and 10 total pods installed.

檢查安裝成功

疑問1?

當tag版本未改變,修改了本地代碼,pod install可否更新成功?

若是不能,是否須要將pod file文件中引用該庫註釋先刪除,再添加執行兩次pod install?你們能夠嘗試一下。

或者直接pod update嘗試一下

疑問2?

若是咱們本身的組件裏面,

s.dependency  ' AFNetworking', "~> 3.0.0"

應該在工程文件podfile地方須要先pod  AFNetworking。

若是有其餘的問題的話,往後慢慢改正。

解決問題的過程當中踩的坑:

一、svn服務器沒有設置JSPatchtest的tags,項目podfile文件裏面的來源寫上了tag 引發的錯誤

$ pod install
Analyzing dependencies
Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`, tag `0.0.1`

[!] Error installing JSPatchtest
[!] /usr/bin/svn export --non-interactive --trust-server-cert --force https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest/tags/0.0.1 /var/folders/rg/gmjp61bx0x95t4tjx2hh_3sr0000gn/T/d20170106-35146-108d7q8

svn: E170000: URL 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest/tags/0.0.1' doesn't exist

二、考慮到SVN上面每一個人都有本身的帳號和密碼,s.source       = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}是基於個人帳號的,製做的過程當中,我曾經輸過密碼。假如我將其改爲:s.source       = { :svn => "https://yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"} 會是怎麼樣的狀況呢?通過團隊其餘人員的測試,不須要密碼,一切OK.

相關文章
相關標籤/搜索