CocoaPods Common Issues
Issues with Installing CocoaPods
Execute pod --version to check if CocoaPods is installed and view the version number.
If command not found: pods appears, it means CocoaPods has not been installed yet.
Open Terminal (⌘ + Space, type Terminal to open the terminal), and execute:
sudo gem install cocoapodsFor more details, please refer to CocoaPods Getting Started.
If you cannot download and install CocoaPods due to network issues, consider using Ruby Gems mirror source:
- Tsinghua Gems Mirror: https://mirror.tuna.tsinghua.edu.cn/help/rubygems/
- Ruby China Mirror: https://gems.ruby-china.com
Issues with Connecting to trunk CDN
Since version 1.8, CocoaPods uses trunk CDN (https://cdn.cocoapods.org/) as the spec source by default. The original intention is very good, avoiding the need to locally clone a large Specs repository, which would require a full update every time. However, it may not be possible to access this trunk CDN domestically.
Common issues:
-
When executing
pod install, the errorCDN: trunk URL couldn't be downloadedis reported. -
When executing
pod repo update, the errorCDN: trunk Repo update failedis reported.
The following are several solutions.
Solution 1: Use a Proxy
Whether using an older version of CocoaPods or using a mirror source, neither is the optimal solution. To fully utilize the features of CocoaPods, the most recommended solution is to use a proxy to solve the problem of not being able to connect to the trunk CDN.
Solution 2: Use an Older Version of CocoaPods
CocoaPods version 1.7.5 uses Specs as the repo source by default. You can uninstall and reinstall an older version of CocoaPods.
- Uninstall:
sudo gem uninstall cocoapods- Install CocoaPods 1.7.5:
sudo gem install cocoapods -v 1.7.5Solution 3: Manually Switch to Using Official Git Source/Mirror Source
This solution is not recommended as it is more cumbersome.
-
Check the current source being used
First execute
pod repo listto see what sources are on your machine. If there is a master source (URL: https://github.com/CocoaPods/Specs.git) and a trunk source (URL: https://cdn.cocoapods.org/), you don't need to perform the second step below. You can directly executepod repo remove trunkto delete the trunk CDN source.If using version 1.9.1 or above, there should only be one trunk CDN source. In this case, you need to manually add a Git source.
-
Add source
-
Add Official CocoaPods Git Source.
Execute
pod repo add cocoapods https://github.com/CocoaPods/Specs.git. -
Add Tsinghua CocoaPods Mirror Source.
Execute
pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git.
-
-
Execute
pod repo update --verbose. -
Specify the source in the
Podfilefile in the root directory of the iOS project.
If you cannot find Podfile, please first cd into the root directory of the iOS project and execute pod init.
Add a line source https://xxxxx.git to the first line of Podfile (where the URL is the URL of the source added in the previous step).
Example: Using Tsinghua source
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
target 'MyProject' do
use_frameworks!
endIf you don't specify source in the Podfile, CocoaPods version 1.8 and above will automatically re-add and use the trunk CDN source. Therefore, each project's Podfile needs to explicitly specify the source, which is very cumbersome.
Issues with pod install Unable to Find the Project
When executing pod install, you may encounter the following error: Unable to find a specification for "XXXXXX" or CocoaPods could not find compatible versions for pod "XXXXXX"
The following are several solutions.
Solution 1: Update Index
-
Execute
pod repo update --verboseto update the index. -
Then execute
pod update XXXXXXto update the library (XXXXXXis the name of the specific library that reported the error in the prompt). -
Finally, execute
pod installto reinstall.
Solution 2: Delete Index File and Reload
-
Execute
pod setup. -
Then execute
rm ~/Library/Caches/CocoaPods/search_index.jsonto delete the index file. -
Finally, execute
pod installto reinstall (may take a long time).
