创建Pods私有库

Pods私有库创建步骤

  1. 创建私有 Spec Repo    
  2. 创建Pod项目工程文件
  3. 创建podspec文件
  4. 本地测试podsspec文件
  5. 向Spec Repo提交podspec
  6. Pod库使用
  7. 更新维护posspec

 名词解释:

  repo(repository):私有仓库

  spec(specification):pod的描述文件,是描述整个库的远吗的依赖关系和编译规则

   repo创建

  • 在github/公司的git服务器上创建一个空的git项目。eg:helloRepo
  • git clone https://githu.com/xxx/helloRepo
  • cd helloRepo/
  • pod repo add helloRepo xxx/helloRepo.git 【pod repo add[private repo name][github https clone URL]】

  repo 删除

  • pod repo remove helloRepo

  repo 更新

  •  pod repo update  #默认更新所有repo
  •  pod repo update hello Repo #更新制定的repo

spec 创建

  • pod spec creat <name>

  

  spec 编辑(以AFNetworking为例)

Pod::Spec.new do |s|
s.name = 'AFNetworking'
s.version = '3.2.1'
s.license = 'MIT'
s.summary = 'A delightful iOS and OS X networking framework.'
s.homepage = 'https://github.com/AFNetworking/AFNetworking'
s.social_media_url = 'https://twitter.com/AFNetworking'
s.authors = { 'Mattt Thompson' => 'm@mattt.me' }
s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => s.version, :submodules => true }
#tag指向version,是否有子模块
s.requires_arc = true s.public_header_files = 'AFNetworking/AFNetworking.h' #需要引入的公共头文件
s.source_files = 'AFNetworking/AFNetworking.h' #文件路径 pch_AF = <<-EOS
#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif
#ifndef TARGET_OS_TV
#define TARGET_OS_TV 0
#endif
EOS
s.prefix_header_contents = pch_AF #适用版本
s.ios.deployment_target = '7.0'
s.osx.deployment_target = '10.9'
s.watchos.deployment_target = '2.0'
s.tvos.deployment_target = '9.0' s.subspec 'Serialization' do |ss|
ss.source_files = 'AFNetworking/AFURL{Request,Response}Serialization.{h,m}'
#AFURL{Request,Response}Serialization 表示文件名为AFURL开头,包含有Request或Response字符串并以Serialization结尾的文件名。
ss.public_header_files = 'AFNetworking/AFURL{Request,Response}Serialization.h'
#需要应用的系统库
ss.watchos.frameworks = 'MobileCoreServices', 'CoreGraphics'
ss.ios.frameworks = 'MobileCoreServices', 'CoreGraphics'
ss.osx.frameworks = 'CoreServices' #如果要用第三方framework
#ss.vendor_framworks = 'thirdSdk.framwork'
#如果用到第三方.a
#ss.vendor_libraries = 'third.a'
end s.subspec 'Security' do |ss|
ss.source_files = 'AFNetworking/AFSecurityPolicy.{h,m}'
ss.public_header_files = 'AFNetworking/AFSecurityPolicy.h'
ss.frameworks = 'Security'
end s.subspec 'Reachability' do |ss|
ss.ios.deployment_target = '7.0'
ss.osx.deployment_target = '10.9'
ss.tvos.deployment_target = '9.0' ss.source_files = 'AFNetworking/AFNetworkReachabilityManager.{h,m}'
ss.public_header_files = 'AFNetworking/AFNetworkReachabilityManager.h' ss.frameworks = 'SystemConfiguration'
end s.subspec 'NSURLSession' do |ss|
ss.dependency 'AFNetworking/Serialization'
ss.ios.dependency 'AFNetworking/Reachability'
ss.osx.dependency 'AFNetworking/Reachability'
ss.tvos.dependency 'AFNetworking/Reachability'
#需要依赖的子仓库
ss.dependency 'AFNetworking/Security' ss.source_files = 'AFNetworking/AF{URL,HTTP}SessionManager.{h,m}', 'AFNetworking/AFCompatibilityMacros.h'
ss.public_header_files = 'AFNetworking/AF{URL,HTTP}SessionManager.h', 'AFNetworking/AFCompatibilityMacros.h'
end s.subspec 'UIKit' do |ss|
ss.ios.deployment_target = '7.0'
ss.tvos.deployment_target = '9.0'
ss.dependency 'AFNetworking/NSURLSession' ss.public_header_files = 'UIKit+AFNetworking/*.h'
ss.source_files = 'UIKit+AFNetworking'
end
end

  

  spec 编译

  • pod lib lint 本地教研pod创建时候正常,执行此命令会根据spec文件配置编译静态库,如果没有报错则表示通过。

   pod lib lint && pod spec lint

   lint 常用参数:

  1. --sources 编译时需要用到的源码地址。
  2. --use--libraries 编译加载以来的其他静态库。
  3. --allow--warning 编译时允许有警告,如果不设置,出现任何警告都会编译失败。
  4. --verbose 显示编译详细信息。
  5. eg:pod lib lint --sourses=git@10.101.168.28:mobile-ios/xmllibs.git.master --user-libraries --verbose。
  6. pod lib lint 编译的源码来自当前podspec所在目录而不是podspec中source所指定的git的地址。
  7. pod spec lint 联网校验,通过source中的git地址获取源码,同时还会校验git地址上时候有对应的version字段的tags。

**pod lib lint

   will lint your pod locally.and will just ensure that you did provide everything property to create your pod.But it will not be enough to validate your pod.

   **pod spec lint

   will lint your pod anywhere.it`s mean buy that you can have your pod source code on github for example ant it will lint.if the pod spec lint returns without erros,

   you can push the lintedpod spec to cocoa pods.

   TD;DR: pod lib lint = local,pod spec lint = local/remote 

  

  spec 提交

  • 将源码库中的改动(podspec),提交到git  
  • 新建tag,名字对应podspec中指定的version字段。
  • 添加podspec至pod repo
  • pod repo push [pod repo xx] xx.podspec
  • podspec文件必须lint验证通过后才能提交到spec repo
  • 提交前先提交本地源码到对应的git,并创建好对应的tags

 pod使用 

# Uncomment the next line to define a global platform for your project
platform :ios, '8.0' #如果第一个条件满足就不会去下一个资源地址去搜索
source 'https://github.com/xxx/hello.Repo.git'
source 'https://github.com/CocoaPods/Specs.git target 'HelloSpec' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks! # Pods for HelloSpec
#如果后面跟路径,这忽略上面设置的资源路径
pod 'AFNetworking' #, :path==>'User/xxx/Desktop/cocoapods/AFNetworking' end

  

上一篇:Linux安装VM虚拟机


下一篇:Redhat Linux 部署maven环境