当前位置:   article > 正文

CocoaPods - podspec私有库配置_pod_target_xcconfig

pod_target_xcconfig

Specs源

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

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

查看 CocoaPods 的 repos 与 Caches

  1. ~/.cocoapods/repos/ # repos
  2. ~/Library/Caches/CocoaPods/ # Caches
  1. pod install --repo-update # 更新本地repo,并pod install
  2. pod install --no-repo-update # pod install,不更新repo
  3. pod repo update # 默认更新所有repo
  4. pod repo update ~/.cocoapods/repos/master # 更新指定repo
  5. pod search YYKit # 查询YYKit的相关Specs信息

工程引用

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

  1. source 'https://github.com/zhengmiaokai/Specs.git'
  2. pod 'JPUtils', '~> 1.0.0'

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

  1. post_install do |installer|
  2. installer.pods_project.targets.each do |target|
  3. if target.name == 'JPUtils'
  4. target.build_configurations.each do |config|
  5. config.build_settings['CODE_SIGN_IDENTITY'] = ""
  6. end
  7. end
  8. end
  9. end

git仓库创建

1)源码仓库

2)Specs仓库

podspec文件配置

name:私有库包名

s.name = 'JPUtils'

version:当前版本号

s.version = '1.0.1'

platform:最低支持系统

s.platform = :ios, '8.0'

source:源码git地址、标签

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

requires_arc:是否为arc

s.requires_arc = true

source_files:代码源文件路劲

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

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

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

libraries:系统libs

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

vendored_libraries:内置libs路径

  1. s.vendored_libraries = 'JPUtils/utils/required/tool.a''JPUtils/utils/optional/common.a'   
  2. s.vendored_libraries = 'JPUtils/utils/**/*.a' 

resources: 资源文件地址

  1. s.resources = 'JPUtils/utils/resource.bundle'
  2. s.resources = 'JPUtils/utils/*.bundle'

frameworks:系统frameworks

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

vendored_frameworks:内置frameworks路径

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

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

  1. s.dependency  'AFNetworking'   
  2. s.dependency  'MKNetwork'

 valid_archs:当前私有库支持的处理器

  1. valid_archs = ['x86_64', 'arm64e', 'arm64', 'armv7s', 'armv7']
  2. # arm64e:iPHone XS,iPHone XR,iPhone 11, ...
  3. # arm64:iPhone5s,iPhone6、7、8,iPhone6、7、8 Plus,iPhone X,...
  4. # armv7s:iPhone5, iPhone5C,iPad4,...
  5. # armv7:iPhone 3GS,iPhone4,iPhone 4s,iPad,iPad2,iPad3,...

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

  1. s.pod_target_xcconfig = { :OTHER_LDFLAGS => '-lObjC',
  2. :CLANG_CXX_LANGUAGE_STANDARD => 'c++11',
  3. :CLANG_CXX_LIBRARY => 'libc++',
  4. :VALID_ARCHS => 'x86_64 arm64e arm64 armv7s armv7' }
  5. # :OTHER_LDFLAGS等价于'OTHER_LDFLAGS'
  6. # :VALID_ARCHS等价于'VALID_ARCHS'

user_target_xcconfig: pod库的Build Settings配置

  1. s.user_target_xcconfig = { 'OTHER_LDFLAGS' => '-lObjC',
  2. 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
  3. 'CLANG_CXX_LIBRARY' => 'libc++',
  4. 'VALID_ARCHS' => 'x86_64 arm64e arm64 armv7s armv7' }
  5. # user_target_xcconfig:对工程中所有 pod 的设置
  6. # pod_target_xcconfig:对当前 pod 的设置
  7. # 如果多个 pod 的 podspec 中对 user_target_xcconfig 同⼀个值进行了设置,会存在冲突的问题

subspec :pod子模块配置

  1. s.subspec 'catogerys' do |ss|
  2. ss.source_files = "component/catogerys/**/*.{h,m}"
  3. ss.dependency "JPUtils"
  4. end
  5. s.subspec 'controllers' do |ss|
  6. ss.source_files = "component/controllers/**/*.{h,m}", "component/utils/**/*.{h,m}"
  7. ss.dependency "component/catogerys"
  8. end

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

podspec文件校验、上传

1)创建远程仓库 

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

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

  1. pod repo add zhengmiaokai https://github.com/zhengmiaokai/Specs.git
  2. 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,多个地址用逗号隔开)

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/529882
推荐阅读
相关标签
  

闽ICP备14008679号