系统配置 终端错误信息都很好2019.6.21 更新:更新系统Mac OS 10.15 Beta 版 出现的问题
根据错误信息提示知道是cocoapods路径问题
解决方案1: 执行
brew link --overwrite cocoapods
上面的方案报错
方案2 执行
brew reinstall cocoapods
brew install ruby
brew link --overwrite cocoapods
2019.4.26 更新:本地建立私有库 执行 pod search 操作失败
➜ ~ pod search AFNetworking
### Command
/usr/local/bin/pod search AFNetworking
### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack
CocoaPods : 1.7.0.beta.3
Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
RubyGems : 2.5.2.3
Host : Mac OS X 10.14.4 (18E226)
Xcode : 10.2.1 (10E1001)
Git : git version 2.20.1 (Apple Git-117)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : BestSpecs - https://gitlab.bestpay.com.cn/mbp/sdk-ios-podspec.git @ 73e2d9ea1ffbb7b856355478ab35723127f37748
master - https://github.com/CocoaPods/Specs.git @ 64c4782ec389c4040aa1b4b948da9f15fa78549a
### Plugins
cocoapods-deintegrate : 1.0.3
cocoapods-packager : 1.5.0
cocoapods-plugins : 1.0.0
cocoapods-search : 1.0.0
cocoapods-stats : 1.0.0
cocoapods-trunk : 1.3.1
cocoapods-try : 1.1.0
### Error
JSON::ParserError - 784: unexpected token at 'nagement"],"密码管理SDK":["BestPasswordManagement"],"密码管理":["BestPasswordManagement"],"life-is-a-boat":["BestPasswordManagement"],"liubing-it@bestpay.com.cn":["BestPasswordManagement"]},"com-mbp-sdk-ios-passwordmanagement":{}}'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:252:in `stored_search_index'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:184:in `updated_search_index'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:115:in `search_by_name'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:87:in `local_search'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:63:in `run'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.0.beta.3/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.0.beta.3/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=784%3A+unexpected+token+at+%27nagement%22%5D%2C%22%E5%AF%86%E7%A0%81%E7%AE%A1%E7%90%86SDK%22%3A%5B%22BestPasswordManagement%22%5D%2C%22%E5%AF%86%E7%A0%81%E7%AE%A1%E7%90%86%22%3A%5B%22BestPasswordManagement%22%5D%2C%22life-is-a-boat%22%3A%5B%22BestPasswordManagement%22%5D%2C%22liubing-it%40bestpay.com.cn%22%3A%5B%22BestPasswordManagement%22%5D%7D%2C%22com-mbp-sdk-ios-passwordmanagement%22%3A%7B%7D%7D%27&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
Looking for related issues on cocoapods/cocoapods...
Found no similar issues. To create a new issue, please visit:
https://github.com/cocoapods/cocoapods/issues/new
本地search_index 问题,解决办法是删除该文件即可
sudo rm /Library/Caches/CocoaPods/search_index.json
2018.12.4 更新:系统更新导致cocoapods使用出错
升级macOS Mojave之后,cocoapods不能正常使用了,这是苹果一贯的问题,遇到大版本系统升级,之前的一些软件就不能正常使用了。
终端输入
sudo gem update –system
显示如下错误
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /usr/bin directory.
解决办法:
输入一下命令:
sudo gem install -n /usr/local/bin cocoapods
2018.9.22 更新:ruby 地址更新
参照:https://gems.ruby-china.org
1.安装指南
安装方式异常简单 , Mac 下都自带 ruby,使用 ruby 的 gem 命令即可下载安装:
$ sudo gem install cocoapods
$ pod setup
另外,ruby 的软件源 https://rubygems.org 因为使用的是亚马逊的云服务,所以被墙了,需要更新一下 ruby 的源,使用如下代码将官方的 ruby 源替换成国内淘宝的源:
gem sources -l //使用该方法查看本地gem安装的镜像地址
gem sources --remove https://rubygems.org/
~~gem sources -a https://ruby.taobao.org/~~
gem sources --add https://gems.ruby-china.com/
gem sources -l
还有一点需要注意,pod setup在执行时,会输出Setting up CocoaPods master repo,但是会等待比较久的时间。这步其实是 Cocoapods 在将它的信息下载到 ~/.cocoapods目录下,如果你等太久,可以试着 cd 到那个目录,用du -sh *来查看下载进度。你也可以参考本文接下来的使用 cocoapods 的镜像索引一节的内容来提高下载速度。
然后执行安装命令
在项目目录下创建文件Podfile
仿照下规则书写
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
Tip: CocoaPods provides a pod init command to create a Podfile with smart defaults. You should use it.
执行下命令给项目安装cocoaPods
$ pod install
2.版本控制
pod 'AFNetworking', '~> 2.6'
执行pod update 更新库 版本控制有一下几种方式:
1)引用第三方库的后边不添加 每次更新为最新的
2)添加 '2.6' 则是注明了第三方库的使用版本为固定的
3)使用'~> 2.6' 说明库的版本为2.6以上的版本 即最新版本
逻辑运算符
'> 0.1' Any version higher than 0.1
'>= 0.1' Version 0.1 and any higher version
'< 0.1' Any version lower than 0.1
'<= 0.1' Version 0.1 and any lower version
乐观的运算符 an optimistic operator ~>:
'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher //0.1.2至0.2
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher //0.1至1.0
'~> 0' Version 0 and higher, this is basically the same as not having it.
3.
cocoapods 使用常见的问题
1.安装第三方库在项目中导入的时候提示找不到文件
这个一般情况下是在build settings -->search paths header search paths --> User Header Search Paths 添加 $(PODS_ROOT) 选择:recursive(会在相应的目录递归搜索文件)
网友评论