CocoaPods - podspec私有库配置

Specs源

CocoaPods Specs 源地址:原始仓库-github、镜像仓库-gitee

source 'https://github.com/CocoaPods/Specs.git' # 原始仓库

source 'https://gitee.com/mirrors/CocoaPods-Specs.git' # 镜像仓库(每日同步一次)

查看 CocoaPods 的 repos 与 Caches

~/.cocoapods/repos/ # repos

~/Library/Caches/CocoaPods/ # Caches
pod install --repo-update # 更新本地repo,并pod install

pod install --no-repo-update # pod install,不更新repo

pod repo update # 默认更新所有repo

pod repo update ~/.cocoapods/repos/master # 更新指定repo

pod search YYKit # 查询YYKit的相关Specs信息

工程引用

Podfile 中添加私有库的 source、pod 配置,在终端输入 pod install 构建

source 'https://github.com/zhengmiaokai/Specs.git'

pod 'JPUtils', '~> 1.0.0'

 在 Podfile 中使用 post_install 自定义 pod 库的 Build Settings

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'JPUtils'
            target.build_configurations.each do |config|
                config.build_settings['CODE_SIGN_IDENTITY'] = ""
            end
        end
    end
end

git仓库创建

1)源码仓库

2)Specs仓库

podspec文件配置

name:私有库包名

s.name = 'JPUtils'

version:当前版本号

s.version = '1.0.1'

platform:最低支持系统

s.platform = :ios, '8.0'

source:源码git地址、标签

s.source = { :git => 'git地址', :tag => 'JPUtils_1.0.1' }  
#等价于:s.source = { 'git' => 'git地址', 'tag' => 'JPUtils_1.0.1' }

requires_arc:是否为arc

s.requires_arc = true

source_files:代码源文件路劲

s.source_files = 'JPUtils/utils/required/*.{h.m}', 'JPUtils/utils/optional/*.{h.m}'  

s.source_files = 'JPUtils/utils/**/*.{h.m}'

 public_header_files:公共头文件路径(默认值:source_files配置的头文件)

s.public_header_files = 'JPUtils/public/header/*.h'  

libraries:系统libs

s.libraries = 'sqlite3', 'stdc++'  
#等价于:s.libraries = ['sqlite3', 'stdc++']

vendored_libraries:内置libs路径

s.vendored_libraries = 'JPUtils/utils/required/tool.a', 'JPUtils/utils/optional/common.a'   

s.vendored_libraries = 'JPUtils/utils/**/*.a'  

resources: 资源文件地址

s.resources = 'JPUtils/utils/resource.bundle'

s.resources = 'JPUtils/utils/*.bundle'

frameworks:系统frameworks

s.frameworks = ['UIKit', 'Foundation']

vendored_frameworks:内置frameworks路径

s.vendored_frameworks = 'JPUtils/utils/required/tool.framework', 'JPUtils/utils/optional/common.framework'

s.vendored_frameworks = 'JPUtils/utils/**/*.framework' 

dependency:关联第三方库、组件库,s.dependency  'MKNetwork', '~> 1.0.2'版本号在Podfile中声明,避免多个podspec出现不一致的情况

s.dependency  'AFNetworking'   
s.dependency  'MKNetwork'

 VALID_ARCHS:私有库支持的处理器

s.pod_target_xcconfig = { 'VALID_ARCHS' => 'arm64e arm64 armv7s armv7' }

# arm64e:iPHone XS,iPHone XR,iPhone 11, ...
# arm64:iPhone5s,iPhone6、7、8,iPhone6、7、8 Plus,iPhone X,...
# armv7s:iPhone5, iPhone5C,iPad4,...
# armv7:iPhone 3GS,iPhone4,iPhone 4s,iPad,iPad2,iPad3,...

EXCLUDED_ARCHS:私有库不支持的处理器

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS' => 'x86_64 i386' }

# 官方推荐使用EXCLUDED_ARCHS,VALID_ARCHS仍然可以使用

pod_target_xcconfig:当前私有库的Build Settings配置

s.pod_target_xcconfig = { :OTHER_LINK_FLAG => '$(inherited) -ObjC',
  :CLANG_CXX_LIBRARY => "libc++",
  'VALID_ARCHS[sdk=iphone*]' => 'arm64 arm64e',
  'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

# :OTHER_LINK_FLAG等价于'OTHER_LINK_FLAG'
# 'VALID_ARCHS[sdk=iphone*]':iPhone真机支持的处理器类型
# 'EXCLUDED_ARCHS[sdk=iphonesimulator*]':iPhone模拟器不支持的处理器类型

user_target_xcconfig:工程Target / Pods-Target的Build Settings配置

s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

# 在多个私有库的user_target_xcconfig中,同个Key设置了不同的值会导致配置冲突

subspec :pod子模块配置

s.subspec 'catogerys' do |ss|
   ss.source_files = "component/catogerys/**/*.{h,m}"
   ss.dependency "JPUtils"
end

s.subspec 'controllers' do |ss|
   ss.source_files = "component/controllers/**/*.{h,m}", "component/utils/**/*.{h,m}"
   ss.dependency "component/catogerys"
end

备注:文件路径中 * 表示文件名通配符, ** 表示文件夹递归匹配;数组用逗号隔开(如: s.libraries = 'a', 'b' 或者 s.libraries = ['a', 'b'] )

podspec文件校验、上传

1)创建远程仓库 

https://github.com/zhengmiaokai/Specs.git 

2)使用远程仓库URL在repos中添加repo 

pod repo add zhengmiaokai https://github.com/zhengmiaokai/Specs.git

pod repo remove zhengmiaokai # 移除repo

3)检验podspecs文件的有效性 

pod spec lint ~/desktop/zhengmiaokai/JPUtils/JPUtils.podspec --use-libraries --allow-warnings --verbose --sources='私有库-git地址,CocoaPods-git地址'

pod spec lint ~/desktop/zhengmiaokai/JPUtils/JPUtils.podspec --use-libraries --allow-warnings --verbose --sources='https://github.com/CocoaPods/Specs.git,https://github.com/zhengmiaokai/Specs.git'

4)podspec文件添加到远程仓库 

pod repo push zhengmiaokai ~/desktop/zhengmiaokai/JPUtils/JPUtils.podspec --use-libraries --allow-warnings --verbose --sources='私有库-git地址,CocoaPods-git地址'

pod repo push zhengmiaokai ~/desktop/zhengmiaokai/JPUtils/JPUtils.podspec --use-libraries --allow-warnings --verbose --sources='https://github.com/CocoaPods/Specs.git,https://github.com/zhengmiaokai/Specs.git'

备注:--use-libraries (使用libraries和frameworks)、--allow-warnings(忽略警告)、--verbose(定位错误)--sources='specs地址'(默认为CocoaPods,多个地址用逗号隔开)

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值