2021-6-9更新:
Mac M1處理器在安裝cocoapods時(shí),會(huì)發(fā)生以下錯(cuò)誤
LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle, 0x0009): missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
錯(cuò)誤提示
LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle, 0x0009): missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
解決辦法:
在應(yīng)用程序-實(shí)用工具里,打開終端 顯示簡介
2.勾選以Rosetta方式打開

- 運(yùn)行 sudo gem install cocoapods (之前安裝過就略過)
- 運(yùn)行 sudo gem install ffi
- 最后pod install


報(bào)錯(cuò) :沒有權(quán)限問題 在命令行語句執(zhí)行前加sudo
背景:Mac OS Catalina 10.15.1 Xcode11.2.1
Cocoapods 版本:1.8.4
暴露問題:
1、pod install 命令出現(xiàn)問題
2、trunk 分支問題
3、cocoapods 源不穩(wěn)定問題
解決:問題太多 決定卸載重裝 記錄流程。
卸載:
1、卸載cocoapods
問題1:在cocoapod 執(zhí)行卸載 語句
sudo gem uninstall cocoapods
的時(shí)候 While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
改為:
sudo gem uninstall -n /usr/local/bin cocoapods
2、卸載本地cocoapods相關(guān)的插件
執(zhí)行:
gem list --local | grep cocoapods
查詢相關(guān)插件 如下圖所示:

逐個(gè)刪除相關(guān)插件:
sudo gem uninstall cocoapds-core
sudo gem uninstall cocoapods-deintegrate
sudo gem uninstall cocoapods-downloader
sudo gem uninstall cocoapods-plugins
sudo gem uninstall cocoapods-search
sudo gem uninstall cocoapods-stats
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try
...
3、查看gem 更新ruby源地址
這里官方簡易盡可能的使用比較新的RubyGems版本,建議2.6.x以上
//更新gem
gem update --system # 這里請翻墻一下
//查詢gem 版本
gem -v
查看ruby源
gem sources -l
查詢結(jié)果如下:

因?yàn)槲译娔X本身就是最新的ruby源就不重新裝了 不是上圖中的源 需要移除老的ruby源 更新成這個(gè)
語句如下:
//移除ruby源 XXXXXX代表你查出來的源地址
gem sources --remove XXXXXX
//添加新ruby源
gem sources --add https://gems.ruby-china.com
//查詢是否更新成功
gem sources -l
//確保只有 gems.ruby-china.com
4、安裝Cocoapods
sudo gem install -n /usr/local/bin cocoapods
安裝成功如下圖所示:

5、執(zhí)行pod setup
這步因?yàn)閜od setup 克隆的鏡像源 是國外的 so...換了個(gè)方式 用了國內(nèi)的鏡像 。(如果不換 pod setup 大概率不成功,或下一天可能,浪費(fèi)時(shí)間,本人找了一天的替代源。)這里感謝下 CSDN的大佬的一篇文章,附上文章鏈接Pod setup 太慢終極解決辦法
當(dāng)我們?nèi)?zhí)行pod setup的時(shí)候,會(huì)發(fā)現(xiàn)那是一個(gè)相當(dāng)?shù)穆?。估?jì)一天的時(shí)間都浪費(fèi)再這上面。這是因?yàn)槭褂玫膰獾溺R像,只要使用國內(nèi)的鏡像就很好的解決了。
//查找repo 移除master文件
cd ~/.cocoapods/repos
pod repo remove master
//使用大佬給的國內(nèi)鏡像源
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
你會(huì)發(fā)現(xiàn),那速度,老鐵 6666...
這部分執(zhí)行完后 就是cocoapods的使用了 不多做贅述 都比較熟悉了 我就簡單的寫下流程:
//cd 到項(xiàng)目路徑下
cd xxxxxx
//初始化pod
pod init
//編輯podfile
open Podfile
//編輯完成
pod install
這里有個(gè)問題:
Cocoapods升級到v1.8后pod trunk發(fā)生異常
trunk Repo update failed

我新建立了個(gè)項(xiàng)目,集成了一個(gè)測試的demo, pod里只加了一個(gè)三方庫 集成成功了。但是在自己的項(xiàng)目上出現(xiàn)了這個(gè)問題 。原因是自己項(xiàng)目里集成的第三方太多
解決方案 并不是網(wǎng)上說的把什么trunk刪除 podfile上改source 而是鏈接不穩(wěn)定的問題 遇到這種情況
需要把Podfile上的第三方庫 需要一個(gè)一個(gè)的加三方庫 然后一個(gè)一個(gè)的pod install 多試幾次!?。?直到 pod install成功為止!
2020-05-13 更新:
最近打算把公司項(xiàng)目轉(zhuǎn)成純swift的 ,新建了個(gè)swift 的項(xiàng)目,cocoapods又出問題了 還是 報(bào)trunk Repo update failed問題 在podfile 加了個(gè)source :
source 'https://gitee.com/mirrors/CocoaPods-Specs.git'
完美解決。
問題二:pod install出現(xiàn)警告。
[!] The 168LogisticsSwiftTests [Debug] target overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting defined in Pods/Target Support Files/Pods-168LogisticsSwift-168LogisticsSwiftTests/Pods-168LogisticsSwift-168LogisticsSwiftTests.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the$(inherited)` flag, or
- Remove the build settings from the target.
網(wǎng)上給出的解決方法:

實(shí)際操作一遍 還是會(huì)出現(xiàn)警告
所以,先從這些警告入手, 進(jìn)入工程項(xiàng)目文件夾 ->右鍵點(diǎn)擊 .xcodeproj 文件 顯示包內(nèi)容 -> 打開 .pbxproj 文件 -> 文本搜索提示警告的內(nèi)容 ’ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES’ -> 找到這些內(nèi)容刪除
然后輸入 pod update 進(jìn)行更新
解決了。具體為什么要?jiǎng)h除這個(gè)配置 我百度了一下 沒有找到能解釋的文章 暫時(shí)先照著說的改一下 留待以后追究。
安裝HomeBrew
官網(wǎng)地址 https://brew.sh/index_zh-cn
終端輸入
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
不能用切換國內(nèi)地址
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

——查看版本:brew -v
——安裝軟件:brew install 軟件名
——搜索軟件:brew search 軟件名
——卸載軟件:brew uninstall 軟件名
——更新所有軟件:brew update
——更新具體軟件:brew upgrade 軟件名
——顯示已安裝軟件:brew list
——查看哪些已安裝的程序需要更新: brew outdated
——顯示包依賴:brew reps
——顯示幫助:brew help
===========================================================================
2022-03-01 更新 :因?yàn)楦铝讼到y(tǒng),pod init 創(chuàng)建 Podfile報(bào)錯(cuò):
Command```/usr/local/bin/pod init```
Report* What did you do?* What did you expect to happen?* What happened instead?
解決方法 :更新cocoapods
$ sudo gem update --system
$ sudo gem install cocoapods -n/usr/local/bin