CocoaPods1.0.1依赖库添加方法
自从CocoaPods升级到1.0.1之后,各种坑,之前的link_with语法不能用了,在网上找了好久也没找到解决办法.错误如下:
[!] Invalid `Podfile` file: [!] The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead..
而且我们公司都是快20个target,依赖库都是一样的,Ctrl+c 再 Ctrl+v target 'targetName1' do ... end 这样的语法也是可以解决问题,但是咱们程序员最重要的就是有一颗拒绝复制粘贴的心.
由于Podfile文件是ruby写的,所以我就去网上看了下ruby的语法,写了多个target依赖的库大部分相同的Podfile文件,运行pod install 没问题,全部安装完毕!
编辑工程中的Podfile,根据需求修改库和target名称
多个target公用相同库,还可以添加额外的不同第三方库.
# -*- coding: UTF-8 -*-
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# ruby语法
# target数组 如果有新的target直接加入该数组
targetsArray = ['targetName1', 'targetName2', 'targetName3', 'targetName4', 'targetName5']
# 循环
targetsArray.each do |t|
target t do
pod 'MJRefresh', '~> 1.4.6'
pod 'Masonry', '~> 0.6.1'
end
end
附:
单个target依赖库
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'targetName1' do
pod 'MJRefresh', '~> 1.4.6'
pod 'Masonry', '~> 0.6.1'
end
不同target依赖库
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'targetName1' do
pod 'MJRefresh', '~> 1.4.6'
pod 'Masonry', '~> 0.6.1'
end
target 'targetName2' do
pod 'MJRefresh', '~> 1.4.6'
pod 'Masonry', '~> 0.6.1'
pod 'AFNetworking', '~> 3.0'
end
网友评论
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'tectCplusPlus' do
pod 'AFNetworking', '~> 3.1.0'
pod 'Masonry', '~> 1.0.2'
pod 'MJExtension', '~> 3.0.13'
end
target 'WordMemoryLib' do
pod 'AFNetworking', '~> 3.1.0'
pod 'Masonry', '~> 1.0.2'
pod 'MJExtension', '~> 3.0.13'
end
其中WordMemoryLib是我添加的静态库
发现模拟机无限重启....
您知道咋回事吗
If you want multiple targets to share the same pods, use an abstract_target.
# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
pod 'ShowsKit'
pod 'Fabric'
# Has its own copy of ShowsKit + ShowWebAuth
target 'ShowsiOS' do
pod 'ShowWebAuth'
end
# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do
pod 'ShowTVAuth'
end
end
[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
project 'path/to/Project.xcodeproj'