美文网首页
cocoapods发布开源库记录

cocoapods发布开源库记录

作者: 突刺刺 | 来源:发表于2021-09-03 17:59 被阅读0次

    一.创建一个工程xxx

    • 把需要开源的文件放到这个工程对应文件夹里,保证运行成功。(文件夹也会显示到开源库的目录结构),比如Category文件夹,对应NSURLSession
      WX20210903-143040.png
      WX20210903-143134.png

    二.github创建一个仓库,并把工程xxx与这个仓库绑定(github实在太慢,用coding创建仓库替代了)

    三. 安装CocoaPods

    四.配置.podspec文件

    • 注册:(已经注册的先忽略)

      pod trunk me
      
    • 创建.podspec:

      pod spec create xxx //xxx为开源库的名称
      
    • 编辑.podspec:

      • 开源的一些编辑:
        Pod::Spec.new do |spec|
        spec.name         = "xxx"  //开源库名
        spec.version      = "1.0.0"   //开源版本号,对应仓库的tag
        spec.summary      = "iOS开发组件化" // 简介
        spec.description  = <<-DESC    
                        一些开发组件化   //描述 (DESC不能删掉)
                    DESC    
        spec.homepage     = "https://e.coding.net/xxx.git"   //开源库的仓库地址 
        # spec.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
        
      • 开源协议的编辑:(coding码云没有license,可以到github下载一个放到仓库)
        spec.license      = { :type => "MIT", :file => "LICENSE" }
        
      • 作者信息的编辑:
        #spec.author  = { "tucici" => "00000@qq.com" }
        spec.author    = "tucici"    // 二选一
        
      • 开源库发布的平台的编辑:
        spec.platform    = :iOS  //这里设置只发布iOS平台
        # spec.platform     = :ios, "5.0"
        #  When using multiple platforms
        # spec.ios.deployment_target = "5.0"
        # spec.osx.deployment_target = "10.7"
        # spec.watchos.deployment_target = "2.0"
        # spec.tvos.deployment_target = "9.0"
        
      • 开源库的资源编辑:
        spec.source = { :git => "#{spec.homepage}", :tag => "#{spec.version}" }
        
        • 其他常见的写法:
          spec.source = { :git => "https://github.com/xxx/xxx.git", :commit => "98emfox" }
          spec.source = { :git => "https://github.com/xxx/xxx.git", :tag => 1.0.0 }
          spec.source = { :git => "hhttps://github.com/xxx/xxx.git", :tag => spec.version }
          
          • commit => "98emfox"表示pod版本与git仓库指定的commit= 98emfox绑定
          • tag => 1.0.0表示pod版本与git仓库指定的tag=1.0.0绑定
          • tag => spec.version表示pod版本与仓库的tag保持一致。spec.version就是.podspec最开始编辑参数spec.version = "1.0.0"
      • 开源库需要包含的源文件:
        spec.source_files  = "CCKit", "CCKit/Category/*.{h,m}" 
        spec.exclude_files = "Classes/Exclude"
        # spec.public_header_files = "Classes/**/*.h"   //需要包含的头文件
        

        CCKit文件夹是与.podspec同一级,上面配置的结果是,开源库会包含CCKit/Category/里面所有的.h.m文件

      • 开源库依赖静态库/动态库的编辑:
        spec.frameworks = "Foundation", "UIKit"  //这里就只依赖官方库
        
      • 依赖第三方开源库的编辑:
        spec.dependency "AFNetworking", "~> 1.0.0"
        
      • 大体上配置就这样,其实看.podspec的注释,可以大概明白每个配置是干嘛的

    五.验证.podspec

    pod spec lint xxx.podspec --verbose
    
    • 验证成功提示:
      xxx.podspec passed validation.
      

    六.成功发布

    • 发布:
      pod trunk push xxx.podspec
      
    • 成功:
      Updating spec repo `trunk`
      
      -------------------------------------------------------------------- ------------
      🎉  Congrats
      
      🚀  xxx (1.0.0) successfully published
      📅  September 3rd, 04:29
      🌎  https://cocoapods.org/pods/xxxx
      👍  Tell your friends!
      
    • 搜索发布的开源库xxx:
      rm ~/Library/Caches/CocoaPods/search_index.json
      

      过几分钟后,搜索,就能成功显示,有时候可能需要等更久:

      pod search XXX
      

    七.错误及解决:

    • Specs satisfying the `xxxx (~> 1.0.0)` dependency were found, but they required a higher minimum deployment target.:
      解决: 三方依赖库xxxx设置里支持最低的ios版本,所以本开源库设置ios版本要高于xxxx支持的ios版本
    • Encountered an unknown error (/usr/bin/xcrun simctl list -j devices:
      解决: Xcode->Preferences->Locations->Command line tools,选择一个Xcode版本
    • [!] The spec did not pass validation, due to 3 warnings (but you can use `--allow-warnings` to ignore them).:
      解决:
      pod spec lint xxx.podspec --verbose --allow-warnings
      

    相关文章

      网友评论

          本文标题:cocoapods发布开源库记录

          本文链接:https://www.haomeiwen.com/subject/gqahwltx.html