上傳自己庫到Cocoapods和遇見的各種問題解決

第一步,上傳自己寫好的代碼讓別人去下載。先安裝Cocoapods 

   端口輸入:sudo gem install cocoapods  安裝完成後。開始註冊trunk

第二步,註冊trunk最好賬戶和郵箱和github賬戶和綁定郵箱一致,代碼如下

  端口輸入:pod trunk register [email protected]  '賬戶名'  --verbose 回車

第三步,去你上一步填寫的郵箱去驗證,會收到郵箱,將郵件裏面的地址復出出來,在瀏覽器上面打開就可以了。完事後請輸入一下代碼在端口:

  端口輸入:pod trunk me 看到如下信息:

這裏我們看到你所需要的信息,Pods 這是現實None 沒有上傳過任何代碼,等後期你上次成功後可以再來打開看看就懂了。

第四步,期初完成,我們接下來可以去github去先創建你要上次代碼的文件文本如下:

這裏期初沒有這些代碼數據,可以在這裏創建也可以github官方上次工具直接上次就可以,工具如下:

登錄自己的github賬戶和密碼,可以將你要上傳的代碼直接拖進去,或者自己手動添加進去,這時候點擊Push 上傳就可以如下:

完成這樣我們就看見我第一張上傳的圖片那樣了,你們第一次上傳沒有podspec文件還有LICENSE文件。接下來我們去創建剩下所需要的文件。

第五步,創建podspec文件和配置podspec文件。

在端口數據:pod spec create xxxxxx.podspec 記得你輸入這個的時候必須在你項目的目錄之內纔行。如:

在項目中看見xxxx.podspec 文件說明創建成功,接下來我去配置文件如下:

這裏給大家介紹一下上面配置的各個對應的信息。

s.name = ""  這裏填寫你上傳的項目文字

s.version = "0.0.1" 你的第一個版本號。

s.summary = "" 這裏寫你項目的詳細介紹和使用方法,

s.description = "版本控制數據" 這裏填寫具體信息

s.homepage = "https://github.com/13662049573/TFY_Model" 這裏填寫你github下載地址

s.license = "MIT" 這裏是官方規定寫這個就可以。

s.author = { "tianfengyou" => "[email protected]" } 這裏寫你自己剛纔註冊trunk的時候賬戶和郵箱就可以

s.platform = :ios,'10.0'  這裏是寫你項目支持的最低版本。

s.source = { :git => "https://github.com/13662049573/TFY_Model.git", :tag => 'v0.0.1'} 這裏寫你github上面的下載地址和版本號控制。

s.source_files = "TFY_Model/TFY_ModelKit/*.{h,m}" 這裏配置最重要的,文件路徑後面對這裏遇見問題和配置的更多詳細信息。

s.requires_arc = true 這裏是否支持ARC 

s.frameworks = "UIKit"  涉及的庫多庫可以用,隔開。

s.ios.deployment_target = "9.0"

這個podspec配置完成後,我去配置一個LICENSE 文件這裏將下面創建一個文字爲LICENSE的文件,然後將下面的代碼賦值進去改一下你的個人信息保存就可以了,代碼如下:


The MIT License (MIT)

Copyright (c) 2019 田風有 The MIT License (MIT)

Copyright (c) 2019 田風有

Copyright (c) 2019-2026 YJSettingTableView Software Foundation (https://github.com/13662049573/TFY_Model)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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.

 

第六步,完成這兩個文件的配置然後我去github去創建一個上傳路徑和必須要的操作:如下:

你們進入看到的release這裏顯示的是0,然後點擊進去這裏。

點擊這裏然後就看到如下:

上面都配置完和按照要求填寫完成後,我們回到端口這裏,進行驗證和調試。如下:

端口輸入: pod lib lint xxx.podspec --allow-warnings --use-libraries

回車:進行驗證你的配置和路徑是否正常

等看到passed validation說明驗證成功,

第七步,接下來我們開始上傳代碼瞭如下:

端口代碼:pod trunk push xxxxxx.podspec --allow-warnings --use-libraries

這裏和前面我們檢查的時候都要加上,--allow-warnings --use-libraries 爲嘛一會我給你說這裏遇見的很多問題並加以解釋。

這裏會上傳我們需要等待,這個基礎上會出現很多問題,接下來我給你大家詳細分析和解決遇見的問題、

第八步。CocoaPods 操作過程中出現的錯誤

錯誤1,最常見的錯誤

ERROR | [iOS] file patterns: The source_filespattern did not match any file.
出現這個錯誤,是source_files下面的文件不對,之前網上找的podspec文件出錯,目前這個沒發現。如果出現這個錯誤,就去修改source_files的文件路徑就可以了。不要按照xcode裏面看到的路徑寫,要寫物理路徑,打開文件夾去查看。一般規則就是:
source_files:這裏要注意的是這裏的路徑是以xxx.podspec文件爲根據,同級的話,就寫文件名就好(一般要傳pod的最外層文件夾和xxx.podspec文件是同級的)。往後多級的,逐級加。如果多個的話,就分組加,逗號隔開。下面針對各種情況給出範例:

1、同級的文件夾B裏面只有.h和.m文件
source_files = "B/*.{h,m}"
2、多級文件夾B/C/D(只有最後一級文件夾裏面有.h和.m文件
source_files = "B/C/D/*.{h,m}"
3、多級文件夾B/C/D,每個文件夾裏面都有.h和.m文件
source_files = "B/*.{h.m}","B/C/*.{h.m}","B/C/D/*.{h.m}"
其中C D可以用**代替

錯誤2 

Unable to accept duplicate entry for: TestProject_hu (1.0.0)
這個錯誤的出現是說明git上的版本和你的xxx.podspec文件裏的version不一致,這個時候最好雙方都修改下。成功的機率會高點。一個git的tag修改下,xxx.podspec裏的version也修改下。git打的版本一定要和xxx.podspec文件中的version一致。


錯誤3

ERROR | xcodebuild: /Users/xinhuikeji/Library/Developer/Xcode/DerivedData/App-cpgccqdjhyrbqwcpjanyefntolkf/Build/Products/Release-iphonesimulator/wLib/wLib.framework/Headers/BaseModel.h:13:9: error: include of non-modular header inside framework module 'wLib.BaseModel' [-Werror,-Wnon-modular-include-in-framework-module]

出現場景:pod驗證podspec文件的時候,如果.h文件裏面有引用第三方pod,會出現這個錯誤

解決方式:在命令後面添加--use-libraries就可以了
pod lib lint xxx.podspec --allow-warnings --use-libraries

錯誤4

上傳到pod的時候,想要出現圖中這樣的文件層級,這個時候就需要在xxx.podspec文件裏面用到一個subspec的屬性

#s.source_files = 'TQKit/Classes/**/*'

s.subspec 'Tool' do |ss|
      ss.source_files = 'TQKit/Classes/Tool/TQMacro.h'
  end

  s.subspec 'TQApi' do |ss|
      ss.source_files = 'TQKit/Classes/TQApi/*.{h,m}'
      ss.dependency 'TQKit/Tool'
      ss.dependency 'YTKNetwork'
  end
  
  s.subspec 'TQCategory' do |ss|
      ss.source_files = 'TQKit/Classes/TQCategory/*.{h,m}'
  end
  
  s.subspec 'TQTableView' do |ss|
      ss.source_files = 'TQKit/Classes/TQTableView/*.{h,m}'
  end

這裏我的s.source_files是註釋掉的,是因爲我的TQKit下面所有的文件都在我下面定義的文件夾裏面,所以就不需要寫這個路徑了。如果TQKit下面有一個公共的頭文件,這樣的話可以寫成s.source_files = 'TQKit/Classes/xxx.h';
注意到這段代碼:

s.subspec 'TQApi' do |ss|
      ss.source_files = 'TQKit/Classes/TQApi/*.{h,m}'
      ss.dependency 'TQKit/Tool'
      ss.dependency 'YTKNetwork'
  end

裏面有兩個引用的效果,這是因爲TQApi裏面會用到這兩個庫,所以要在自己的下面進行引用。

  • 一個是引用當前TQKit裏面有的文件 TQMacro.h文件,但是這個文件不在TQApi下面,所以要進行引用。再者上面已經把TQMacro.h文件放到Tool裏面,所以這裏引用Tool文件夾就可以,或者也可以寫成'TQKit/Tool/TQMacro.h'

s.subspec 'Tool' do |ss|
ss.source_files = 'TQKit/Classes/Tool/TQMacro.h'
end

  • 一個是引用一個pod第三方庫 YTKNetwork,pod第三方庫引用就簡單了,不需要寫路徑,直接寫庫名就可以。

錯誤5

  • 調用終端命令

pod lib lint --allow-warnings --use-libraries

如果是swift語言的話,則有可能出現下面的錯誤:

-> BaseComponent (0.1.0)
    - WARN  | [iOS] swift_version: 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`

[!] BaseComponent did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
You can use the `--no-clean` option to inspect any issue.

  • 解決方法:終端使用echo "2.3" > .swift-version命令即可

錯誤6


  • 在執行指令git push -u origin master的時候,會出現下述錯誤:

    錯誤6

這個錯誤時說本地庫的文件和遠程庫的文件不對應,可以按照下述方式解決:

  • 1、執行指令git pull --rebase origin master,然後再push
  • 2、上述操作還是不行的話,就執行強制覆蓋,執行git push -f origin master

錯誤7

執行指令pod trunk push xxx.podspec的時候,報下面錯誤

There was an error pushing a new version to trunk: getaddrinfo: nodename nor servname provided, or not known
解決方案:出現這個錯誤,是網絡DNS錯誤,去設置->網絡->雷劈以太網->高級設置->DNS設置成114.114.114.114

錯誤8

在對podspec文件進行驗證pod spec lint的時候,有時候會出現下面的錯誤

錯誤8-1


這種錯誤大多數出現在創建私有庫的過程中,當前的私有庫依賴了其他的私有庫,在驗證的時候沒有知道私有庫的源地址。
解決方法:
上面已經提到這種情況出現在我們驗證私有庫的時候,該私有庫依賴其他私有庫,但是沒有指定依賴私有庫的源地址,所以我們在驗證的時候加上一個參數--sources,這個--sources指定的源地址一個是我們的私有庫地址,一個是pods的公有庫地址
https://github.com/CocoaPods/Specs.git

圖8-2

 

錯誤9

在執行git push origin master的時候,如果指定origin的源地址是https的,可能會出現下面的錯誤

`HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large`

出現這個錯誤需要做的就是更換origin源地址

git remote set-url origin ssh地址

錯誤10. ERROR | spec: The specification defined in `LZTool.podspec` could not be loaded.

MacBook:PodTest Artron_LQQ$ pod lib lint LZTool.podspec

 -> LZTool.podspec
    - ERROR | spec: The specification defined in `LZTool.podspec` could not be loaded.


[!] Invalid `LZTool.podspec` file: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...<-DESC 這是一個測試文檔, 這裏主要是描述類庫...
...                               ^
LZTool.podspec:28: syntax error, unexpected '\n', expecting '='.

 #  from LZTool.podspec:27
 #  -------------------------------------------
 #    #   * Finally, don't worry about the indent, CocoaPods strips it!
 >    s.description  = <<-DESC 這是一個測試文檔, 這裏主要是描述類庫的功能設計初衷介紹
 #                     DESC
 #  -------------------------------------------


[!] LZTool.podspec did not pass validation, due to 1 error.
[!] 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`.
You can use the `--no-clean` option to inspect any issue.
MacBook:PodTest Artron_LQQ$

這個錯誤是使用指令pod lib lint LZTool.podspec檢查文件是否合法時發生的;

可以看出是在設置s.description字段時發生的錯誤, 當時的寫法是:

s.description  = <<-DESC LZTool 是一個用於保存一些常用工具類的工具 DESC

以爲可以吧他們併到一行, 導致一直報這個錯, 後來寫成兩行, 還是報錯, 最後才試出這樣寫纔對:

s.description  = <<-DESC 
                          LZTool 是一個用於保存一些常用工具類的工具
                   DESC

錯誤11. [iOS] file patterns: The `source_files` pattern did not match any file.

MacBook:PodTest Artron_LQQ$ pod lib lint LZTool.podspec

 -> LZTool (0.0.1)
    - WARN  | github_sources: Github repositories should end in `.git`.
    - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

[!] LZTool did not pass validation, due to 1 error and 1 warning.
[!] 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`.
You can use the `--no-clean` option to inspect any issue.
MacBook:PodTest Artron_LQQ$

這個錯誤也是使用指令pod lib lint LZTool.podspec檢查文件是否合法時發生的;

這個是在指定共享的類庫時, 文件路徑不對, 也就是設置s.source_files字段時, 發生了錯誤, 這裏的路徑是相對於LZTool.podspec文件的, 如果是與LZTool.podspec同級的文件夾, 直接寫文件夾名稱即可, 如:

 s.source_files = "LZTool"

如果有多級目錄, 一定要逐級添加. 這裏也可以這麼寫:

 s.source_files = "LZTool/*.{h,m}"

如果,在某個版本的tag下報此錯誤,更改爲正確路徑後,還是報此錯誤,可嘗試新建一個新的tag;

錯誤12. fatal: Remote branch 0.0.1 not found in upstream origin

MacBook:PodTest Artron_LQQ$ pod spec lint

 -> LZTool (0.0.1)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/LQQZYY/PodTest.git /var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n --template= --single-branch --depth 1 --branch 0.0.1

Cloning into '/var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n'...
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
[!] 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`.
MacBook:PodTest Artron_LQQ$

這個是使用指令pod spec lint來檢查文件是否可用時發生的錯誤;

這是因爲在你託管代碼的庫裏(這裏是指github)找不到這個分支, 也就是在編輯 LZTool.podspec時, 裏面的字段 s.versons.source中的 taggithub創建的release版本號不一致導致, 修改爲一樣即可!

這裏還有另外一個解決方法方法二

錯誤13. 加載xib問題

PS: 這個不是我個人遇到的問題, 是在文章中看到, 這裏記錄一下;
如果通過cocoapods下載的類庫中含有Xib文件, 使用原來的方式初始化就不起作用了:

[[[NSBundle mainBundle] loadNibNamed:@"xibName" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"xibName" bundle:nil] forCellWithReuseIdentifier:@"ZLCollectionCell"];

應該使用下面這種方式初始化:

#define kZLPhotoBrowserBundle [NSBundle bundleForClass:[self class]]
[[kZLPhotoBrowserBundle loadNibNamed:@"ZLPhotoActionSheet" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"ZLCollectionCell" bundle:kZLPhotoBrowserBundle] forCellWithReuseIdentifier:@"ZLCollectionCell"];

這樣就能正常使用了;

錯誤14.加載圖片資源問題

PS: 這個問題我嘗試了一個demo, 直接設置了s.resources = "LZScaner/images/*.png", 圖片也能正常顯示( 可參考我設置的podspec文件LZScaner.podspec)沒有遇到這個問題, 但是還是把這個方式記錄一下吧...

如果通過代碼"[UIImage imageNamed:@"picName"]"去設置圖片的話,則圖片資源有可能無法正常顯示, 可通過以下方式解決:

  • 創建bundle資源目錄
command+N -> Resource -> Settings Bundle

刪除bundle攜帶的無用文件,把圖片資源添加到bundle資源內

  • 改變代碼圖片路徑
// 圖片路徑
#define kZLPhotoBrowserSrcName(file) [@"ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
#define kZLPhotoBrowserFrameworkSrcName(file) [@"Frameworks/ZLPhotoBrowser.framework/ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
kZLPhotoBrowserSrcName(file) 爲通過copy文件夾方式獲取圖片路徑的宏
kZLPhotoBrowserFrameworkSrcName(file) 爲通過cocoapods下載安裝獲取圖片路徑的宏
  • 然後修改代碼中設置圖片的方式如下
UIImage *img = [UIImage imageNamed:kZLPhotoBrowserSrcName(@"img.png")]?:[UIImage imageNamed:kZLPhotoBrowserFrameworkSrcName(@"img.png")];

podspec地址: ZLPhotoBrowser.podspec可以參考學習!

錯誤15. trunk: getaddrinfo: nodename nor servname provided, or not known

MacBook:LZScaner Artron_LQQ$ pod trunk register [email protected] --description= 'LZScaner'
[!] There was an error registering with trunk: getaddrinfo: nodename nor servname provided, or not known
MacBook:LZScaner Artron_LQQ$

出現這個原因是, 我開了APN, 把APN關了, 重新啓動一下網絡就好了...

錯誤16. xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information

MacBook:LZSortTool Artron_LQQ$ pod spec lint

 -> LZSortTool (0.0.1)
    - WARN  | [iOS] license: Unable to find a license file
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - NOTE  | [iOS] xcodebuild:  LZSortTool/LZSortToolDemo/LZSortToolDemo/LZSortClass/LZSortTool.m:14:9: fatal error: 'ChineseToPinyin.h' file not found

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error and 1 warning.
[!] 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`.
MacBook:LZSortTool Artron_LQQ$

這個是執行 pod spec lint指令的時候產生的錯誤:

這個錯誤從- NOTE可以看出, 是項目中的這個文件ChineseToPinyin.h找不到, 回到項目, 編譯一下也會報這個錯. 是因爲我修改了本地文件中的這個文件的路徑, 項目中引用的還是原先的路徑, 打開左側文件列表, 可以發現這個文件是紅色的, 刪除引用, 重新添加, 然後到你的github上面, 重新添加一個release版本, 再重新執行指令即可驗證通過.

錯誤17. 驗證成功後搜索不到新加的支持庫

如果在製作支持庫的過程中沒有錯誤, 或者最好添加庫驗證通過, 即出現下面這個界面:

 

上傳成功

在使用

pod search LZTool

的時候, 搜索不到這個庫, 或者在使用時找不到這個庫, 可以使用下面的指令來清理一下緩存:

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

然後再去使用, 基本就可以了.

錯誤18. ERROR | name: The name of the spec should match the name of the file.

LQQ-MacBook-Pro:LQWebViewSwift LQiqiang$ pod lib lint LQWebViewSwift.podspec

 -> LQWebView-Swift (1.0)
    - ERROR | name: The name of the spec should match the name of the file.
    - ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `LQWebView-Swift` in `/Users/LiuQiqiang/Desktop/SourcesTree/Cocoapods/LQWebViewSwift`) during validation.

[!] LQWebView-Swift did not pass validation, due to 2 errors.
You can use the `--no-clean` option to inspect any issue.
LQQ-MacBook-Pro:

出現這個錯誤是因爲,我的podspec文件名稱和裏面設置的 ** s.source_files** 和 s.name不一致導致的,修改爲一致的即可!

本地檢測代碼倉庫是否有問題

pod lib lint --allow-warnings --use-libraries
遠程檢測代碼倉庫是否有問題

pod spec lint --allow-warnings --use-libraries
向遠程代碼索引庫提交spec

pod trunk push --allow-warnings --use-libraries

# 1 註冊
pod trunk register [email protected] '用戶名' --description='描述' --verbose

# 下邊是拓展,不再步驟中
# 2 查看註冊信息
pod trunk me
# 3 添加其他維護者
pod trunk add-owner XXXSDK [email protected]
# 4 刪除已發的版本
pod trunk delete XXXSDK 版本號
# 5 刪除某個pod
pod trunk deprecate XXXSDK
# 6 刪除其他維護者
pod trunk remove-owner XXXSDK [email protected]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章