文章目录
Pod 命令
1、CocoaPods版本查看
pod --version
2、安装升级CocoaPods
sudo gem install cocoapods
如果报权限错误,执行以下命令
sudo gem install -n /usr/local/bin cocoapods
3、创建Podfile
$ vim Podfile
platform :ios, '9.0'
target "CocoapodsDemo" do
pod "AFNetworking"
pod 'Masonry'
end
注:冒号和ios是连着的,中间没有空格,有空格会报错。
esc取消输入,:wq退出编辑
4、添加第三方库(添加、更新、移除第三方库都用这个)
pod install
添加后我遇到一下提示信息
[!] The `CocoapodsDemo [Debug]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `CocoapodsDemo [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `CocoapodsDemo [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `CocoapodsDemo [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.release.xcconfig'. This can lead to problems with the CocoaPods installation
解决方法:
在自己的项目的Target->build setting->搜索HEADER_SEARCH_PATHS,
在Header Search Paths中添加$(inherited);
搜索OTHER_LDFLAGS,在Other Linker Flags中添加$(inherited)
然后再执行 pod install,添加完成。
参考文章:CocoaPods的安装与使用
5、查看第三方库信息
pod search AFNetworking
5.1 pod search 报错
[!] CDN: trunk - Cannot perform full-text search because Algolia returned an error: 0: Cannot reach any host: execution expired, execution expired, execution expired, execution expired
解决方法
5.1.1 在Podfile中指定源地址
source 'https://github.com/CocoaPods/Specs.git'
5.2.2 移除trunk
pod repo remove trunk
再执行 pod search xxx 就可以了
6、查看项目组第三方库版本信息
cat Podfile.lock
PODS:
- AFNetworking (3.2.1):
- AFNetworking/NSURLSession (= 3.2.1)
- AFNetworking/Reachability (= 3.2.1)
// AFNetworking内容太多了,就显示一部分吧
- Masonry (1.1.0)
- MJRefresh (3.1.15.7)
- Reachability (3.2)
- YYCache (1.0.4)
- YYModel (1.0.4)
// 中间内容省略
COCOAPODS: 1.9.3
2、Podfile 设置
2.1、关闭cocoapods中的第三方库的警告提示
platform :ios, '9.0'
inhibit_all_warnings!
参考文章:iOS 开发去除 CocoaPods 警告(Fix Xcode Warning)
2.2、设置pod的buildsettings
...
target "xxxxxx" do
pod 'xxxxx'
...
...
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
3、问题记录
3.1 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES
[!] The `CocoapodsDemo [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `CocoapodsDemo [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-CocoapodsDemo/Pods-CocoapodsDemo.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
解决方法:有问题的是CocoapodsDemo这个Target,在Build setting里搜索ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES,添加$(inherited)。debug和release都要添加。
参考:The XXXUITests [Debug]
target overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES
build…
3.2 镜像地址
清华镜像
效果不太好,改用码云的镜像。
https://gitee.com/mirrors/CocoaPods-Specs.git
操作流程
$ cd ~/.cocoapods/repos
$ pod repo remove master
$ git clone https://gitee.com/mirrors/CocoaPods-Specs.git master
Podfile 源地址
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
因为trunk的原因会报
Found multiple specifications for `CocoaLumberjack (3.7.0)`:
- /Users/apple/.cocoapods/repos/master/Specs/d/1/8/CocoaLumberjack/3.7.0/CocoaLumberjack.podspec.json
- /Users/apple/.cocoapods/repos/trunk/Specs/d/1/8/CocoaLumberjack/3.7.0/CocoaLumberjack.podspec.json
移除trunk
pod repo remove trunk