安裝使用,涉及一些命令總結(jié),可跳過
--------復制粘貼專用區(qū)Begin
1.CocoaPods 安裝
本不想寫,但方便我部署新機器安裝CocoaPods的時候順手能拷貝。
1.升級ruby包管理工具gem
sudo gem update --system
2.修改gem源鏡像地址
先查看自己電腦的默認的地址,理論上應該是https://rubygems.org/
gem sources -l
刪除默認
gem sources --remove https://rubygems.org/
添加https://gems.ruby-china.org/作為源地址
gem sources -a https://gems.ruby-china.org/
3.安裝命令
執(zhí)行:
sudo gem install cocoapods -n /usr/local/bin 或者
sudo gem install -n /usr/local/bin cocoapods
避免出現(xiàn)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
安裝過程中出現(xiàn)類似/usr/local/bin找不到的報錯,配置一下環(huán)境變量
vim ~/.bash_profile
export PATH=$PATH:/usr/local/bin
source ~/.bash_profile
出現(xiàn)
can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out
這樣的報錯
問題原因以及解決方案:
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license.
The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by
running:
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existent path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:
sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
This should now correctly print:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install should work while that SDK is selected.
To switch back to the current Xcode SDK, use:
sudo xcode-select --switch /Applications/Xcode.app
...趕緊升級10.15就OJBK.
2.Git 一些命令
1.查詢遠程倉庫具體地址
git remote -v
2.打tag相關(guān)的命令
查看tag:
git tag
生成tag:
git tag 0.0.1 指定版本號做tag名字
git tag select_commit_tag 6b359c4 拉取某個commit指定名字作為tag
push tag到遠程git倉庫:
git push --tags push所有本地tag
git push origin 0.0.1 push版本號類型tag
git push origin select_commit_tag push名字類型tag
刪除tag:
git tag -d 0.0.1 本地刪除版本號類型tag
git tag -d select_commit_tag 本地刪除名字類型tag
git push origin :0.0.1 刪除遠程倉庫tag
git push origin :select_commit_tag
3.CocoaPods添加私有倉庫源
CocoaPods默認有一個master的倉庫源,存放所有第三方框架的描述文件podspec(CocoaPods管理第三方框架不是存真正的代碼,而是存每個框架對應的一個描述文件podspec,具體機制自行搜索相關(guān)資料,此處不再多贅述)
如果想要實現(xiàn)各自公司內(nèi)部代碼框架的組件化,就必須創(chuàng)建自己公司私有的的CocoaPods倉庫源,把所有的podspec托管在自己公司的git倉庫。
添加方法:
假設私有倉庫名字:onePrivateRepo
假設私有倉庫地址:https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
執(zhí)行以下命令:
pod repo add onePrivateRepo https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
查看所有倉庫
執(zhí)行命令:
pod repo list
打印結(jié)果:
onePrivateRepo
- Type: git (master)
- URL: https://yourcompany.com/onePrivateRepo/onePrivateRepo.git
- Path: /Users/hanxiaoqing/.cocoapods/repos/onePrivateRepo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/hanxiaoqing/.cocoapods/repos/master
2 repos
Path是本地緩存地址,避免每一次都從倉庫拉取所有的podspec,也就解釋為什么安裝完成cocoapods后,執(zhí)行pod setup會很慢很慢,這個過程就是從master https://github.com/CocoaPods/Specs.git同步到本地的下載過程。
想了解更深的CocoaPods原理機制,參考 iOS系列譯文:深入理解 CocoaPods
--------復制粘貼專用區(qū)End
玩轉(zhuǎn)并深入理解CocoaPods需要補充的一些知識點
1.組件包含c++代碼產(chǎn)生問題
先了解Xcode編譯c++以及設置的一些tips:
Apple 為什么在 Mavericks 里把 C++ 標準庫從 libstdc++ 改成 libc++
實施CocoaPods集成過程中,SDK帶有c++源代碼,無法通過pod lint編譯驗證,提交podspec失敗解決
后續(xù)補充
2.Xcconfig
Xcconfig能夠配置xcode buildsetting的編譯選項,還可以在不同mode下采用不同的配置,有一定的復用性。
使用實例可以參考jspahrsummers/xcconfigs,這個人把所有用法整理到github倉庫,例子很清晰。
其他參考:
Xcode使用xcconfig文件配置環(huán)境
The Unofficial Guide to xcconfig files
3.Header Search Paths
正確認識Header Search Paths,User Header Search Paths,Always Search User Paths,以及
include <>與include " ",參考下面文章
Objective-C 中的 import 和 Search Paths(超級詳細首選)
Xcode增加頭文件搜索路徑的方法
Xcode Search Paths選項配置
4.CocoaPods與工程配置
靜態(tài)庫本質(zhì),自定義靜態(tài)庫包含分類找不到方法的報錯經(jīng)典問題解析,CocoaPods是怎么引用靜態(tài)庫到主工程,參考細聊 Cocoapods 與 Xcode 工程配置
5.Umbrella Header
iOS - Umbrella Header在framework中的應用
CocoaPods實用技巧以及常見問題解決收集
1.Xcode BuildSetting選項的繼承問題
有些時候使用CocoaPods依賴某個庫,寫好podfile,pod install產(chǎn)生警告:
[!] The xxx[Release] target overrides the HEADER_SEARCH_PATHS build setting defined in
Pods/Target Support Files/Pods-xxx/Pods-xxx.release.xcconfig'.
This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
[!] The xxx[Release] target overrides the LIBRARY_SEARCH_PATHS build setting defined in
Pods/Target Support Files/Pods-xxx/Pods-xxx.release.xcconfig'.
This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
打開workspace編譯,還是報錯找不到依賴庫,這很可能是與原主工程BuildSetting的某些選項產(chǎn)生了
沖突,這就涉及到了BuildSetting繼承問題, 要用$(inherited)搞定,具體參考pod install出現(xiàn)Use the xxxx flag警告
2.CocoaPods的一些hook鉤子
pre install hook, post install hook,參考基于 CocoaPods 進行 iOS 開發(fā),里面還有操作pbxproj文件修改build settings的實例。
prepare_command的使用:談談CocoaPods組件二進制化方案
3.自動生成Framework庫工程以及關(guān)聯(lián)Test工程
借助CocoaPods Packager,可以通過自動生成Framework庫工程以及關(guān)聯(lián)Test工程,并跟CocoaPods
無縫結(jié)合,進行組件化管理,參考iOS 利用工具制作Framework庫
4.清理緩存
1.pod install后,會在~/Library/Caches/CocoaPods目錄緩存一份所有install過的庫,在使用CocoaPods過程中,有些時候使用出現(xiàn)死活都摸不到頭腦的問題,比方說podfile明明寫了依賴的庫,CocoaPods也沒問題,執(zhí)行pod install也沒出問題,就是工程build不成功,還是找不到執(zhí)行的庫,那就試試清緩存的命令:
pod cache clean --all 其實等價于 rm -rf ~/Library/Caches/CocoaPods
2.pod install后,會在原來的xcode工程里面加很多東西,為CocoaPods準備舞臺,然后我們都是打開xcworkspace去build,但有的時候想要去除CocoaPods對原來的工程的修改,可以使用:
在目標工程的xcworkspace文件同級目錄,也就是你執(zhí)行pod install的目錄,執(zhí)行:
pod deintegrate
通過觀察輸出打?。?Deleted 1 'Copy Pods Resources' build phases.
Deleted 1 'Check Pods Manifest.lock' build phases.
- libPods-sdkTest.a
- Pods-sdkTest.debug.xcconfig
- Pods-sdkTest.release.xcconfig
Deleting Pod file references from project
- libPods-sdkTest.a
Deleted 1 empty `Pods` groups from project.
Removing `Pods` directory.
Project has been deintegrated. No traces of CocoaPods left in project.
明白了。。。CocoaPods對原工程搞了很多事情。。。
3.終極大清理
清除安裝庫緩存 + 還原原工程 + 去除xcode緩存
pod cache clean --all
pod deintegrate
rm -rf ~/Library/Developer/Xcode/DerivedData/*
這是大招輕易不用的。。。。
5.使用規(guī)范標準總結(jié)
1、第一次獲取pod庫時,應使用pod install。
2、pod outdated和pod update都會更新spec倉庫,但是pod install不會,所以對于經(jīng)常使用的pod庫,建議經(jīng)常pod outdated關(guān)注更新情況。因此,需要更新依賴庫時,先使用pod outdated查看有哪些庫有更新,再使用pod update PODNAME有目的的更新指定庫
3、提交代碼時,請注意一定同時提交Podfile.lock文件,以便其他人能同步到與你相同的pod庫版本。
4、同步其他團隊成員的修改時,請使用pod install。
總結(jié)
重點關(guān)注CocoaPods實用技巧以及常見問題解決收集,其他都是扯淡。。。。
下一篇會講利用我研究,總結(jié)的CocoaPods的一些API,寫一些ruby腳本,擴充CocoaPods功能。。