iOS組件化----Pod私有庫創建及使用

目錄
一、基礎使用
創建私有的pod索引倉庫
創建網絡模塊LeelenNetwork私有庫
使用
注意事項
二、依賴第三方庫
三、設置子庫Subspecs
為什么要設置子庫
子庫格式
子庫的使用
四、組件庫中帶有圖片資源
五、私有庫依賴私有庫
創建公共模塊LeelenPlatform私有庫
設置LeelenPlatform私有庫依賴LeelenNetwork私有庫

一、基礎使用

創建私有的pod索引倉庫

1、在公司的git服務器上創建私有遠程索引倉庫??寺〉刂啡纾?code>http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git

2、新建pod spec索引倉庫(將私有的遠程倉庫copy到本地)。命令如下:

pod repo add LeelenIotPodSpecs http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git

LeelenIotPodSpecs為pod spec索引倉庫名稱

http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git為遠程索引倉庫克隆地址。

3、執行完畢后,在目錄:/Users/admin/.cocoapods/repos 下會多出來一個LeelenIotPodSpecs文件夾,可使用pod repo命令查看。如下:

#自己創建的本地索引私有庫
LeelenIotPodSpecs
- Type: git (master)
- URL:  http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git
- Path: /Users/admin/.cocoapods/repos/LeelenIotPodSpecs

#默認存在的git本地索引庫
trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/admin/.cocoapods/repos/trunk

2 repos

至此,私有遠程索引倉庫LeelenIotPodSpecs生成完成

創建網絡模塊LeelenNetwork私有庫

1、在公司的 git 服務器上面創建 LeelenNetwork 的 git 遠程倉庫,克隆地址是:http://192.***.*.**:****/leelen-ios-platform/LeelenNetwork.git

2、創建私有的pod組件庫(如LeelenNetwork網絡組件),執行如下命令:pod lib create LeelenNetwork。過程中需要填一些選項,按需選擇即可。如下:

admindeiMac:~ admin$ pod lib create LeelenNetwork
Cloning `https://github.com/CocoaPods/pod-template.git` into `LeelenNetwork`.
Configuring LeelenNetwork template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What platform do you want to use?? [ iOS / macOS ]
 > iOS

What language do you want to use?? [ Swift / ObjC ]
 > ObjC

Would you like to include a demo application with your library? [ Yes / No ]
 > Yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > None

Would you like to do view based testing? [ Yes / No ]
 > Yes

What is your class prefix?
 > LL
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

Running pod install on your new library.

Analyzing dependencies
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing LeelenNetwork (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `LeelenNetwork.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'LeelenPlatform/Example/LeelenNetwork.xcworkspace'

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
admindeiMac:~ admin$ 

pod組件空模板創建成功后會自動打開工程。

3、刪除ReplaceMe文件,將需要封裝的文件(如網絡組件相關文件)復制到 LeelenNetwork/LeelenNetwork/Classes中。如下:將LeelenNetworkManager復制到Classes中。

3.png

4、修改 LeelenNetwork.podspec 文件如下:

Pod::Spec.new do |s|
  s.name             = 'LeelenNetwork' # 名稱
  s.version          = '1.0.1' # 版本號
  s.summary          = '網絡請求模塊' # 概述
  s.homepage         = 'https://github.com/hjq/LeelenNetwork'  # 主頁
  s.license          = { :type => 'MIT', :file => 'LICENSE' }  # license證書
  s.author           = { 'hjq' => 'h*j*q*@leelen.cn' } # 作者
  s.source           = { :git => 'http://192.***.*.**:****/leelen-ios-platform/LeelenNetwork.git', :tag => s.version.to_s }  # 源代碼地址
  s.ios.deployment_target = '10.0' # iOS版本
  s.source_files = 'LeelenNetwork/**/*.{h,m}' # 源碼所在路徑
end

5、校驗本地索引文件 LeelenNetwork.podspec

cd到LeelenNetwork.podspec所在文件夾下,執行pod lib lint --allow-warnings,該命令是檢查本地索引文件是否符合推送規則。成功了會打印LeelenNetwork.podspec passed validation。如下:

admindeiMac:LeelenNetwork admin$ cd /Users/admin/LeelenNetwork
admindeiMac:LeelenNetwork admin$ pod lib lint --allow-warnings

 -> LeelenNetwork (1.0.1)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/hjq/LeelenNetwork) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

LeelenNetwork passed validation.
admindeiMac:LeelenNetwork admin$ 

如有報錯,按提示修改。

pod lib lint參數解析:

--sources:需要引?的spec,默認只依賴master,如果當前pod依賴了私有庫,需要將其對應的spec包含進來,不然會報找不到對應庫的問題。參數可以是本地spec的名稱,也可以是git地址。

--allow-warnings:有警告會通過不了,如果警告是?關緊要的,可以加上,讓檢測通過。

--verbose:打印詳細的檢驗過程

--use-libraries:?程或者依賴??了靜態庫(*.a?件)或者是framework

備注:

pod lib lint 表示在本地校驗索引文件

pod spec lint 表示在本地和遠程都校驗索引文件

6、將1創建的遠程倉庫克隆下來,將2-5創建及修改后的LeelenPlatform放到克隆下來的文件夾中,運行工程,沒問題后提交到git。如下:

4.png

7、上傳 LeelenNetwork.podspec 索引文件到我們的私有遠程索引倉庫 LeelenIotPodSpecs,命令如下:

pod repo push LeelenIotPodSpecs LeelenNetwork.podspec --allow-warnings

上面命令對 LeelenNetwork.podspec 文件做了兩個操作:一個是將其推送到私有的遠程索引倉庫,可以去公司的 git 上面 LeelenIotPodSpecs 索引倉庫中查看;另一個是將其 copy 到私有的本地索引倉庫,這個可以去目錄:/Users/admin/.cocoapods/repos/LeelenIotPodSpecs 下查看到。

終端顯示如下:

admindeiMac:~ admin$ cd /Users/admin/Documents/LeeLen/LeelenNetwork
admindeiMac:LeelenNetwork admin$ pod repo push LeelenIotPodSpecs LeelenNetwork.podspec --allow-warnings

Validating spec
 -> LeelenNetwork (1.0.1)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/hjq/LeelenNetwork) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Updating the `LeelenIotPodSpecs' repo


Adding the spec to the `LeelenIotPodSpecs' repo

 - [Add] LeelenNetwork (1.0.1)

Pushing the `LeelenIotPodSpecs' repo


[!] 'LeelenNetwork' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.
admindeiMac:LeelenNetwork admin$ 

至此私有的組件庫LeelenNetwork就創建完成了,可以在終端執行 pod search LeelenNetwork來查詢它。

使用

在項目工程中修改podfile文件,并pod install

source 'http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git'
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

platform :ios, '10.0'

target 'LeeLenIOT' do
pod 'LeelenNetwork', '~>1.0.1'
end

注意事項

1、操作的時候,先cd到對應的文件夾下

2、注意操作順序

a、在develop分支開發、修改LeelenNetwork代碼,修改 LeelenNetwork.podspec版本號,提交。

b、將develop分支合并到master。

c、在master打tag(如:1.0.1),注意這邊的tag應與LeelenNetwork.podspec中的s.version 版本號一致。

二、依賴第三方庫

當我們的私有庫需要依賴其它第三方才可以正常使用時,我們就需要在spec索引文件中開啟依賴。例如下面所示代碼,表明當前倉庫需要依賴AFNetworking和SDWebImage。

Pod::Spec.new do |s|
  s.name             = 'LeelenNetwork'
  s.version          = '1.0.3'
  s.summary          = '網絡請求模塊'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'hjq' => 'h*j*q*@leelen.cn' }
  s.source           = { :git => 'http://192.168.1.10:9099/leelen-ios-platform/LeelenNetwork.git', :tag => s.version.to_s }
  s.ios.deployment_target = '10.0'
  s.source_files = 'LeelenNetwork/**/*.{h,m}'
  
  #設置第三方依賴
  #s.dependency 'AFNetworking'
  s.dependency 'AFNetworking', '~> 3.2.0'
  s.dependency 'SDWebImage', '~> 4.3.3'
end

修改完spec索引之后,執行pod lib lint --allow-warnings檢查本地索引文件是否符合推送規則。然后SourceTree提交代碼,打tag(tag注意與LeelenNetwork.podspec文件內的s.version一致)。執行pod repo push LeelenIotPodSpecs LeelenNetwork.podspec --allow-warnings,上傳 LeelenNetwork.podspec 索引文件到我們的私有遠程索引倉庫 LeelenIotPodSpecs

三、設置子庫Subspecs

為什么要設置子庫

比如LLTool組件下,有兩個功能,一個是網絡請求模塊NetworkManager,一個緩存模塊CacheManager。假設有同事負責的模塊只需要緩存的功能,此時他若pod一整LLTool的話,不但NetworkManager功能對他沒用,而且還需要安裝AFNetworking依賴庫。設置子庫可以很好的解決只使用LLTool組件下的CacheManager部分。

子庫格式

s.subspec '子庫名稱' do |別名|

end

子庫的使用

1、在組件工程中創建子庫

如:在組件LeelenNetwork中創建兩個子庫,分別是NetworkLog和NetworkManager,其中NetworkLog不需要依賴任何第三方庫,內部只有一個log類方法,調用的時候輸出"我不需要依賴別的第三方庫"。NetworkManager依賴AFNetworking,內部有對get和post方法的二次封裝,用于網絡請求。

文件結構如下:

5.png

2、修改LeelenNetwork.podspec索引文件

Pod::Spec.new do |s|
  s.name             = 'LeelenNetwork'
  s.version          = '1.0.4'
  s.summary          = '網絡請求模塊'
  s.homepage         = 'https://github.com/hjq/LeelenNetwork'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'hjq' => 'h*j*q*@leelen.cn' }
  s.source           = { :git => 'http://192.168.1.10:9099/leelen-ios-platform/LeelenNetwork.git', :tag => s.version.to_s }
  s.ios.deployment_target = '10.0'
  
  #之前的樣子
  #源文件
  #s.source_files = 'LeelenNetwork/**/*.{h,m}'
  #設置依賴庫
  #s.dependency 'AFNetworking', '~> 3.2.0'
  
  #修改后的樣子
  #設置子庫(依賴AFNetworking)
  s.subspec 'NetworkManager' do |m|
    m.source_files = 'LeelenNetwork/Classes/NetworkManager/*.{h,m}'
    m.dependency 'AFNetworking'
  end
  
  #設置子庫(不依賴其他第三方)
  s.subspec 'NetworkLog' do |l|
    l.source_files = 'LeelenNetwork/Classes/NetworkLog/*.{h,m}'
  end
  
end

注意:設置子庫時,subspec內使用的是別名,如:s.subspec 'NetworkManager' do |m|的別名是m,則subspec內寫成m.dependency 'AFNetworking',如果寫成s.dependency 'AFNetworking'會校驗不過。

3、修改完spec索引文件之后,執行pod lib lint --allow-warnings檢查本地索引文件是否符合推送規則。校驗沒問題后,SourceTree提交代碼,打tag(tag注意與LeelenNetwork.podspec文件內的s.version一致)。執行pod repo push LeelenIotPodSpecs LeelenNetwork.podspec --allow-warnings操作,上傳 LeelenNetwork.podspec 索引文件到我們的私有遠程索引倉庫 LeelenIotPodSpecs。

4、修改工程中的Podfile文件,cd到工程Podfile文件所在位置,執行pod install

使用NetworkLog功能的Podfile文件修改如下:

source 'http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git'
platform :ios, '10.0'
target 'LeeLenIOT' do
#修改前
#pod 'AFNetworking'
#pod 'LeelenNetwork', '~>1.0.3'
  
#修改后
pod 'LeelenNetwork/NetworkLog', '~>1.0.4'
end

使用NetworkManager功能的Podfile文件修改如下:

source 'http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git'
platform :ios, '10.0'
target 'LeeLenIOT' do
#修改前
#pod 'AFNetworking'
#pod 'LeelenNetwork', '~>1.0.3'

#修改后
pod 'AFNetworking'
pod 'LeelenNetwork/NetworkManager', '~>1.0.4'
end

至此,子庫的配置完成,可在工程中使用子庫了。

注意:由于NetworkManager依賴AFNetworking,所以Podfile文件要pod 'AFNetworking'

四、組件庫中帶有圖片資源

1、將LoginImage文件夾放入/LeelenNetwork/Assets中,其中LoginImage文件夾內有login_logo@2x.png圖片;

2、 修改LeelenNetwork.podspec索引文件

  #設置子庫(不依賴其他第三方)
  s.subspec 'NetworkLog' do |l|
    l.source_files = 'LeelenNetwork/Classes/NetworkLog/*.{h,m}'
    
    #添加圖片資源
    l.resource_bundles = {
      'NetworkLog' => ['LeelenNetwork/Assets/LoginImage/*.png']
    }
  end

3、修改完spec索引文件之后,執行pod lib lint --allow-warnings檢查本地索引文件是否符合推送規則。校驗沒問題后,SourceTree提交代碼,打tag(tag注意與LeelenNetwork.podspec文件內的s.version一致)。執行pod repo push LeelenIotPodSpecs LeelenNetwork.podspec --allow-warnings操作,上傳 LeelenNetwork.podspec 索引文件到我們的私有遠程索引倉庫 LeelenIotPodSpecs。

4、修改工程中的Podfile文件,cd到工程Podfile文件所在位置,執行pod install

5、pod install成功后,可以看到工程中多了一個Resources文件夾,里面有login_logo@2x.png圖片,路徑如下:

Pods/LeelenNetwork/LeelenNetwork/Assets/LoginImage/login_logo@2x.png。以及Products文件夾下多了一個NetworkLog.bundle,查看包內容,發現里面也有login_logo@2x.png圖片。

6、使用時,先拿到最外面的bundle,然后再去找下面指定名字的bundle對象,再搜索具體資源。如下:

NSBundle * currentBundle = [NSBundle bundleForClass:self.class];
NSURL * bundleURL = [currentBundle URLForResource:@"NetworkLog" withExtension:@"bundle"];
NSBundle * resourceBundle = [NSBundle bundleWithURL:bundleURL];
UIImage * logoIcon = [UIImage imageNamed:@"login_logo" inBundle:resourceBundle compatibleWithTraitCollection:nil];

五、私有庫依賴私有庫

創建公共模塊LeelenPlatform私有庫

1、在公司的 git 服務器上面創建 LeelenPlatform 的 git 遠程倉庫,克隆地址是:http://192.***.*.**:****/leelen-ios-platform/LeelenPlatform.git

2、創建私有的pod組件庫,執行如下命令:pod lib create LeelenPlatform。過程中需要填一些選項,按需選擇即可。如下:

admindeiMac:~ admin$ pod lib create LeelenPlatform
Cloning `https://github.com/CocoaPods/pod-template.git` into `LeelenPlatform`.
Configuring LeelenPlatform template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What platform do you want to use?? [ iOS / macOS ]
 > iOS

What language do you want to use?? [ Swift / ObjC ]
 > ObjC

Would you like to include a demo application with your library? [ Yes / No ]
 > Yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > None

Would you like to do view based testing? [ Yes / No ]
 > Yes

What is your class prefix?
 > LL
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

Running pod install on your new library.

Analyzing dependencies
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing LeelenPlatform (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `LeelenPlatform.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'LeelenPlatform/Example/LeelenPlatform.xcworkspace'

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
admindeiMac:~ admin$ 

pod組件空模板創建成功后會自動打開工程。

3、刪除ReplaceMe文件,將需要封裝的文件復制到 LeelenPlatform/LeelenPlatform/Classes中。如下:將Tool文件復制到Classes中。

2.png

4、修改 LeelenPlatform.podspec 文件如下:

Pod::Spec.new do |s|
  s.name             = 'LeelenPlatform'
  s.version          = '1.0.0'
  s.summary          = '公共模塊'
  s.homepage         = 'https://github.com/hjq/LeelenPlatform'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'hjq' => 'h*j*q*@leelen.cn' }
  s.source           = { :git => 'http://192.***.*.**:****/leelen-ios-platform/LeelenPlatform.git', :tag => s.version.to_s }
  s.ios.deployment_target = '10.0'
  s.source_files = 'LeelenPlatform/**/*.{h,m}'
end

5、校驗索引文件 LeelenPlatform.podspec

cd到LeelenPlatform.podspec所在文件夾下,執行pod lib lint --allow-warnings,該命令是檢查本地索引文件是否符合推送規則。成功了會打印LeelenPlatform passed validation.。如下:

admindeiMac:LeelenPlatform admin$ cd /Users/admin/LeelenPlatform
admindeiMac:LeelenPlatform admin$ pod lib lint --allow-warnings

 -> LeelenPlatform (1.0.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/hjq/LeelenPlatform) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

LeelenPlatform passed validation.
admindeiMac:LeelenPlatform admin$ 

如有報錯,按提示修改。

6、將1創建的遠程倉庫克隆下來,將2-5創建及修改后的LeelenPlatform放到克隆下來的文件夾中,運行工程,沒問題后提交到git。如下:

0.png

7、上傳 LeelenPlatform.podspec 索引文件到我們的私有遠程索引倉庫 LeelenIotPodSpecs,命令如下:

pod repo push LeelenIotPodSpecs LeelenPlatform.podspec --allow-warnings

上面命令對 LeelenPlatform.podspec 文件做了兩個操作:一個是將其推送到私有的遠程索引倉庫,可以去公司的 git 上面 LeelenIotPodSpecs 倉庫中查看;另一個是將其 copy 到私有的本地索引倉庫,這個可以去目錄:/Users/admin/.cocoapods/repos/LeelenIotPodSpecs 下查看到。

終端顯示如下:

admindeiMac:~ admin$ cd /Users/admin/Documents/LeeLen/LeelenPlatform
admindeiMac:LeelenPlatform admin$ pod repo push LeelenIotPodSpecs LeelenPlatform.podspec --allow-warnings

Validating spec
 -> LeelenPlatform (1.0.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/hjq/LeelenPlatform) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Updating the `LeelenIotPodSpecs' repo


Adding the spec to the `LeelenIotPodSpecs' repo

 - [Add] LeelenPlatform (1.0.0)

Pushing the `LeelenIotPodSpecs' repo


[!] 'LeelenPlatform' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.
admindeiMac:LeelenPlatform admin$ 

至此私有的 pod 庫創建完成,可以在終端執行 pod search LeelenPlatform來查詢它。

設置LeelenPlatform私有庫依賴LeelenNetwork私有庫

1、修改索引文件LeelenPlatform.podspec里面的依賴為:s.dependency 'LeelenNetwork'

Pod::Spec.new do |s|
  s.name             = 'LeelenPlatform'
  s.version          = '1.0.1'
  s.summary          = '工具組件'
  s.homepage         = 'https://github.com/hjq/LeelenPlatform'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'hjq' => 'h*j*q*@leelen.cn' }
  s.source           = { :git => 'http://192.***.*.**:****/leelen-ios-platform/LeelenPlatform.git', :tag => s.version.to_s }
  s.ios.deployment_target = '10.0'
  s.source_files = 'LeelenPlatform/**/*.{h,m}'
    
  #依賴LeelenNetwork私有庫  
  s.dependency 'LeelenNetwork'  
end

A、修改完spec索引文件之后,執行pod spec lint命令報錯:

 - ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for `LeelenNetwork` depended upon by `LeelenPlatform`

即找不到LeelenNetwork依賴。

B、加上sources源:pod spec lint --sources=LeelenIotPodSpecs 報錯:

- ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for `AFNetworking` depended upon by `LeelenNetwork/NetworkManager`

即找不到AFNetworking依賴。

C、sources源加上pod公有索引庫地址,命令如下:

pod spec lint LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://github.com/CocoaPods/Specs.git

注釋:sources后面跟的參數第一個表示LeelenIotPodSpecs私有索引庫地址,第二個是pod公有索引庫地址。

終端顯示如下:

admindeiMac:LeelenPlatform admin$ pod spec lint LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://github.com/CocoaPods/Specs.git

Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`

很慢...

D、更換國內鏡像(清華園)

pod spec lint LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git --allow-warnings

成功,終端顯示如下:

admindeiMac:LeelenPlatform admin$ pod spec lint LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git --allow-warnings

 -> LeelenPlatform (1.0.1)
    - WARN  | url: The URL (https://github.com/hjq/LeelenPlatform) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Analyzed 1 podspec.

LeelenPlatform.podspec passed validation.


[!] 'LeelenNetwork' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.

[!] 'LeelenPlatform' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.
admindeiMac:LeelenPlatform admin$ 

2、SourceTree提交代碼,打tag(tag注意與LeelenPlatform.podspec文件內的s.version一致)。

3、上傳 索引文件LeelenPlatform.podspec 到我們的私有遠程索引倉庫 LeelenIotPodSpecs,命令如下:pod repo push LeelenIotPodSpecs LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git --allow-warnings操作。

注釋:命令需要帶上LeelenIotPodSpecs私有索引庫地址,和pod公有索引庫地址。否則會報如下錯誤:

 - ERROR | [iOS] unknown: Encountered an unknown error (An unexpected version directory `Classes` was encountered for the `/Users/admin/.cocoapods/repos/1-leelen-ios-platform-leelennetwork/LeelenNetwork` Pod in the `LeelenNetwork` repository.) during validation.

push成功后終端顯示如下:

admindeiMac:LeelenPlatform admin$ pod repo push LeelenIotPodSpecs LeelenPlatform.podspec --sources=http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git --allow-warnings

Validating spec
 -> LeelenPlatform (1.0.2)
    - WARN  | url: The URL (https://github.com/hjq/LeelenPlatform) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Updating the `LeelenIotPodSpecs' repo


Adding the spec to the `LeelenIotPodSpecs' repo

 - [Update] LeelenPlatform (1.0.2)

Pushing the `LeelenIotPodSpecs' repo


[!] 'LeelenNetwork' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.

[!] 'LeelenPlatform' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.
admindeiMac:LeelenPlatform admin$ 

3、工程中使用LeelenPlatform庫

A、Podfile文件添加清華園鏡像,以及LeelenPlatform。修改如下:

source 'http://192.***.*.**:***/leelen-ios-platform/Leelen_specs.git'
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

platform :ios, '10.0'

target 'LeeLenIOT' do
pod 'LeelenNetwork/NetworkLog', '~>1.0.4'
pod 'LeelenPlatform', '~>1.0.2'
end

B、pod install 成功!可以愉快的使用了。終端顯示如下:

admindeiMac:~ admin$ cd /Users/admin/Documents/LeeLen/LeeLenIOT
admindeiMac:LeeLenIOT admin$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (4.0.1)
Installing LeelenNetwork 1.0.4
Installing LeelenPlatform (1.0.2)
Generating Pods project
Integrating client project
Pod installation complete! There are 8 dependencies from the Podfile and 9 total pods installed.

[!] 'LeelenNetwork' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.

[!] 'LeelenPlatform' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.
admindeiMac:LeeLenIOT admin$ 
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,606評論 6 533
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,582評論 3 418
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 176,540評論 0 376
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,028評論 1 314
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,801評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,223評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,294評論 3 442
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,442評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,976評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,800評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,996評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,543評論 5 360
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,233評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,662評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,926評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,702評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,991評論 2 374