美文网首页
(Xcode) 制作 Framework,推送至Cocoapod

(Xcode) 制作 Framework,推送至Cocoapod

作者: 布呐呐u | 来源:发表于2023-06-12 20:25 被阅读0次
注意事项
  • 是否仅构建活动架构,设置为No,即不仅只编译当前所选架构。
    • Build Active Architecture Only
      Build Active Architecture Only.png
  • 设置 Framework 为静态库类型
    • Mach-O Type

      Mach-O Type.png
    • 设置 Framework 为分发而构建,对于Swift,支持Swift标准库的演变和模块接口文件的生成,即提供给他人使用时,Xcode中Swift版本向下兼容,转换 xcframework 需要设置为YES。

      • Build Libraries for Distribution
        Build Libraries for Distribution.png
    • 是否启用死代码剥离,即编译选项优化,对于制作Framework,
      应该设置为No, 不启用代码剥离。

      • Dead Code Stripping
        Dead Code Stripping.png
    • 移除模拟器中生成的arm64架构,非必须操作,模拟器 arm64 与真机arm64 类型不一样,arm64-apple-ios-simulatorarm64-apple-ios

      • Excluded Architecture
        Excluded Architecture.png

校验podspec 文件
  • cd 至 ScanHelper.podspec 文件根目录

    1. 本地校验ScanHelper.podspec 文件内容规范性
    pod lib lint --verbose --allow-warnings --skip-import-validation
    
    1. 联网校验远程组件仓库tag版本与本地待发布版本tag一致性
    pod spec lint --verbose --allow-warnings --skip-import-validation
    

    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.

    • 若工程中依赖私有静态库,则需要 追加 --skip-import-validation指令
    --skip-import-validation
    
    1. 注册账户,可以追加一些描述信息

    pod trunk register + 邮箱 + 用户名 + 可选指令
    Trunk帐户没有密码,只有每台计算机的token令牌

    pod trunk register it@xxxx.com 'Charlie' --description='macbook pro'
    
    1. 点击上述邮件中链接,随后执行如下指令进行校验
    pod trunk me
    
    1. 发布/更新组件,至远程仓库(cocoapods.org)
    pod trunk push ScanHelper.podspec --verbose --allow-warnings --skip-import-validation
    

    推送成功,上述邮件随后会下发通知

    1. 从远程仓库(cocoapods.org)删除已发布组件
    pod trunk delete ScanHelper 0.0.1
    

    [!] CocoaPods could not find compatible versions for pod "ScanHelper"

    • 新版本发布后,且收到邮件提醒,但install 没有下载成功,
      尝试键入如下指令修复问题
    pod cache clean ScanHelper
    pod install --repo-update
    

.podspec 文件,常用键值对及相关规则
Pod::Spec.new do |spec|

  spec.name         = "ScanHelper"
  spec.version      = "0.0.6"
  spec.license      = "MIT"

  spec.summary      = "A lightweight scanning component based on system API in Swift5"
  spec.description  = <<-DESC
             No memory leaks, Support scaling, Support light sense to automatically turn on the flash, Support auto zoom, Support custom UI.
                      DESC

  spec.author       = { "Charlie" => "a51095@hotmail.com" }
  spec.homepage     = "https://github.com/a51095/ScanHelper"
  spec.source       = { :git => "https://github.com/a51095/ScanHelper.git", :tag => spec.version }

  spec.requires_arc = true

  spec.swift_version = "5.0"
  spec.platform      = :ios, "11.0"
  spec.ios.deployment_target = "11.0"

  spec.static_framework = true
  spec.ios.vendored_frameworks  = 'lib/ScanHelperSDK.framework'
  spec.source_files  = "lib/ScanHelperSDK.framework/**/*"
  spec.public_header_files = 'lib/ScanHelperSDK.framework/Headers/ScanHelperSDK-Swift.h'


  # ======================================================
  # spec.ios.exclude_files = 'lib/xxxx.dec' (忽略的文件)
  # spec.source_files  = 'lib/ScanHelperSDK.framework/**/*'(资源文件)
  # spec.public_header_files = 'lib/ScanHelperSDK.framework/Headers/ScanHelperSDK-Swift.h'(Objective-C暴露头文件)
  # ======================================================

  #💡💡💡😈💡💡💡
  # * 匹配所有类型文件
  # *.{h,m} 匹配所有以 .h 和 .m 结尾的文件
  # ** 匹配所有子目录
  #💡💡💡😈💡💡💡

end

常用指令
  • 验证某个 framework, 属于动态库还是静态库
    • 提示current ar archive random library 静态库
    • 提示dynamically linked shared library 动态库
cd xxxx.framework
file xxxx
  • 打包 xcframework
xcodebuild -create-xcframework -framework a.framework -framework b.framework -output xxxx.xcframework

相关文章

网友评论

      本文标题:(Xcode) 制作 Framework,推送至Cocoapod

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