今天创建项目时弹出Cocoapods需要升级提示
顺便记录下升级步骤吧:
1.安装/升级RVM(Ruby Version Manager)
- 先查看RVM版本, 输入命令 rvm -v (注意:输入命令时 最后一位不要多空格,否则会提示找不到)
提示 -bash: rvm: command not found,说明本机没有安装RVM
则需要安装RVM:
1.1 终端输入命令 curl -L get.rvm.io | bash -s stable
出现此图,说明已经安装并使用RVM了,为了安全起见先执行 rvm -v 命令测试一下,就可以看到当前RVM版本啦
- 1.2 用RVM升级Ruby,输入 ruby -v ,查看当前Ruby版本,
输入 rvm list known 查看Ruby所有版本 - 1.3 选择较高版本安装,执行 rvm install 2.4.0 ,安装时报错,尝试多此还是这样
这是由于本机安装了两个Xcode导致
卸载低版本Xcode后再次执行rvm install 2.4.0 后依然报错,报错内容变了,如下
根据提示 configure: error: clang version 3.0 or later is required,我猜测Xcode的命令行工具设置有问题,打开Xcode,果然如此
-
重新设置下
再次执行安装命令,成功安装
至此,RVM终于安装成功了
2.安装新版Cocoapods,执行命令 sudo gem install cocoapods
3.执行命令 sudo gem install cocoapods
4.继续执行命令 sudo gem install cocoapods 时可能会报错,应该执行 sudo gem install -n /usr/local/bin cocoapods
- 继续执行命令 sudo gem install cocoapods命令报错
-
执行 sudo gem install -n /usr/local/bin cocoapods 安装成功
此时新版cocoapods安装成功,输入 pod 命令测试下
此时说明可以正常使用了
补充
-
使用新版cocoapods后podfile文件写法跟以前不一样了
例如,之前是这样写的
执行 pod install 则会报错
- 正确写法应该是
platform :ios, '8.0'
target 'ZQBlockchainWallet' do
pod 'IQKeyboardManager', '~> 4.0.6'
end
执行 pod install ,成功
如果你的项目是swift项目,执行上面写法可能会出现如下错误
解决办法是在 podfile加上 use_frameworks!
platform :ios, '8.0'
target 'ZQBlockchainWallet' do
pod 'IQKeyboardManager', '~> 4.0.6'
use_frameworks! // 加上这句
end
以上写法也可以这样
platform :ios, '8.0'
def pods
pod 'AFNetworking', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.6'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'SnapKit', '~> 3.1.2'
end
target 'MyAppProjName' do
pods
use_frameworks!
end
产生这种错误的原因是 Reference: http://blog.cocoapods.org/CocoaPods-0.36/
Because Apple doesn't let you build static libraries that contain Swift. Unlike Objective-C, Apple doesn't ship the Swift standard runtime libraries with iOS. This decouples the language version from the platform version. When you build an app with Swift, you're responsible yourself to ship them. By default, Xcode uses swift-stdlib-tool to handle copying the Swift runtime dylibs, but the tooling falls short when attempting to ship frameworks that use Swift with an app that is Objective-C only. Your app executable and the frameworks you ship will all use the same set of dylibs, which are embedded into the Frameworks subdirectory of the application bundle.
当项目中有多个target时,可以这样写
use_frameworks!
target 'YourProjectName' do
pod 'SwiftyJSON', '~> 2.1'
pod 'SwiftSpinner', '~> 0.6'
pod 'Alamofire', '~> 1.1'
pod 'SuperRecord', '~> 1.2'
// all other pods goes here
end
target 'YourProjectName1' do
end
target 'YourProjectName2' do
end