iOS假装进步程序员的故事梦想者

CocoaPods|安装流程与使用

2019-09-28  本文已影响0人  夏浩文
系统环境:macOS CataLina 10.15.2

1. 安装 RVM

curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile
rvm -v

2. Ruby升级

ruby -v
rvm list known
rvm install 2.7.0-preview1

3. 更换Ruby源

gem sources -l
gem sources --remove https://ruby.taobao.org/
gem sources -a https://gems.ruby-china.com/

(尾巴这条斜杆需要斟酌移除)

4. 安装CocoaPods

  1. OS X 10.11之前系统的安装cocoapods 指令
$ sudo gem install cocoapods
  1. OS X 10.11以后系统的安装cocoapods 指令
$ sudo gem install -n /usr/local/bin cocoa pods
pod setup
pod --version //查看版本
pod search afnetworking

使用流程

cd 目标路径
pod init
  # Uncomment the next line to define a global platform for your project
platform :ios, '8.0'

target 'ProjectName' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  pod 'AFNetworking'

end
pod install
pod install --no-repo-update

打开白色工程 projectName.xcworkspace

5. 更新CocoaPods

sudo gem install -n /usr/local/bin cocoapods --pre

6. 更新CocoaPods 1.8.+版本本地库

iMac:mac$ pod install
    Analyzing dependencies
    Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
    Downloading dependencies
    Generating Pods project
    Integrating client project
    Pod installation complete! There are 28 dependencies from the Podfile and 32 total pods installed.

附录

PODS:
  - UMCAnalytics (6.0.5):
    - UMCCommon
  - UMCCommon (2.1.1)
  - UMCSecurityPlugins (1.0.6)

问题与解决


更新系统Or Xcode产生的问题
  1. 在更新OS或Xcode之后
    出现 Failed to extract git version from ·git --version· 🔽
macdeMacBook-Air:~ mac$ pod --version
Traceback (most recent call last):
    7: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/ruby_executable_hooks:24:in `<main>'
    6: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/ruby_executable_hooks:24:in `eval'
    5: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/pod:23:in `<main>'
    4: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/pod:23:in `load'
    3: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/bin/pod:55:in `<top (required)>'
    2: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:49:in `run'
    1: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:130:in `verify_minimum_git_version!'
/Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:118:in `git_version': Failed to extract git version from `git --version` ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\\n") (RuntimeError)
xcode-select --install
  1. 更新系统后若发生 No such file or directory🔽
xiaowen:~ natsuhirofumi$ pod --version
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
// 指定缺失路径安装
sudo gem install -n /usr/local/bin cocoapods

更新CocoaPods 1.8+CDN产生的问题

CDN support was first introduced in the 1.7 release and was finalized in 1.7.2. It aims to speed up initial setup and dependency analysis dramatically.

CocoaPods 1.8 switches the CDN as the default spec repo source

  1. RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
    更新本地库出现报错

git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master

///因Coding停止维护,可切别的源~
* https://code.aliyun.com/Magi/CocoaPods.git   
* https://gitclub.cn/CocoaPods/Specs.git `推荐`
  1. 如果pod install中发现:
You have either: 
* out-of-date source repos which you can update with `pod repo update`.
* mistyped the name or version. 
* not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
sudo gem install cocoapods --pre
// 移除本地master
sudo rm -fr ~/.cocoapods/repos/master
// 移除本地缓存
sudo rm -fr ~/Library/Caches/CocoaPods/
-------------方法分隔线-------------
// repos目录
~/.cocoapods/repos/
// 重新setup,如果很慢可使用问题1的解决方法(git clone)
pod setup --verbose

出现最多的连接问题
  1. 更新时,CocoaPods 1.8.0 的trunk连接失败的问题

[!] CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/ Response: 400
或者是
[!] CDN: trunk Repo update failed - 70 error(s): CDN: trunk URL couldn't be downloaded: [库信息], error: Failed to open TCP connection to raw.githubusercontent.com:443
亦或是
[!] CDN: trunk Repo update failed - 14 error(s): CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/[库路径].podspec.json Response: Couldn't connect to server

解决方法一(使用旧下载方式)
//source `源地址`
source 'https://github.com/CocoaPods/Specs.git'
pod repo remove trunk
pod repo list
解决方法二(解决DNS污染问题)
- source 'https://github.com/CocoaPods/Specs.git'
+ source 'https://cdn.cocoapods.org/'
pod repo remove master
ping raw.githubusercontent.com
nslookup raw.githubusercontent.com

----------------------------------->>
Server:     192.168.31.1
Address:    192.168.31.1#53

Non-authoritative answer:
Name:   raw.githubusercontent.com
Address: 151.101.228.133
sudo vi /etc/hosts
// 添加在最后一行
151.101.228.133 raw.githubusercontent.com
如图所示
sudo killall -HUP mDNSResponder
pod install

---皆大欢喜---
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.2.1)
Installing UMCAnalytics (6.0.5)
Installing UMCCommon (2.1.1)
Installing UMCSecurityPlugins (1.0.6)
Generating Pods project
Integrating client project
Pod installation complete! There are 4 dependencies from the Podfile and 4 total pods installed.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
## github
13.250.177.223 github.com
69.171.244.12 github.global.ssl.fastly.net
199.232.28.133 raw.githubusercontent.com (真实ip)
## cocoa
157.230.35.153 cdn.cocoapods.org
~ 
/** 
* 说明:
* 未标记真实ip,直接通过nslookup获取
**/

推广

希望这个头疼的CDN/TRUNK问题解决方法能帮助你们~
顺便推广一下我的香港🇭🇰代购微信号~ 过节送礼找我就对啦~
🌸iYours 🌸
上一篇下一篇

猜你喜欢

热点阅读