CocoaPods - podspec私有库配置

工程引用

Podfile中添加以下cocoaPods指令,在终端输入pod install构建

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

pod 'JPUtils', '1.0.2'

本地存放spec目录

~/.cocoapods/repos/

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(更新指定Specs)

pod search lottie-ios(查询lottie-ios的相关Specs信息)

git仓库创建

1)工程git目录

2)spec目录(通过pod repo自动生成)

podspec文件配置

name:私有库包名

s.name = 'JPUtils'

version:当前版本号

s.version = '1.0.1'

platform:最低支持系统

s.platform = :ios, '8.0'

source:git地址、版本号

s.source = { :git => 'git地址', :tag => '1.0.1' }  
#等价于:s.source = { 'git' => 'git地址', 'tag' => '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:当前私有库支持的处理器

valid_archs = ['x86_64', '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,...

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

s.pod_target_xcconfig = { :OTHER_LDFLAGS => '-lObjC', 
  :CLANG_CXX_LANGUAGE_STANDARD => 'c++11', 
  :CLANG_CXX_LIBRARY => 'libc++', 
  :VALID_ARCHS => 'x86_64 arm64e arm64 armv7s armv7' }

# :OTHER_LDFLAGS等价于'OTHER_LDFLAGS'
# :VALID_ARCHS等价于'VALID_ARCHS'

user_target_xcconfig: pod库的Build Settings配置

s.user_target_xcconfig = { 'OTHER_LDFLAGS' => '-lObjC', 
  'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11', 
  'CLANG_CXX_LIBRARY' => 'libc++', 
  'VALID_ARCHS' => 'x86_64 arm64e arm64 armv7s armv7' }

# user_target_xcconfig:对工程中所有 pod 的设置
# pod_target_xcconfig:对当前 pod 的设置
# 如果多个 pod 的 podspec 中对 user_target_xcconfig 同⼀个值进行了设置,会存在冲突的问题

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地址,https://github.com/CocoaPods/Specs.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,多个地址用逗号隔开)

猜你喜欢

转载自blog.csdn.net/z119901214/article/details/90241251