iOS pod sdk开发到发布,记录

本文章记录从开发sdk到发布cocopod的问题和流程,省的每次都忘还得重新查

1:pod lib create (sdk名称) 命令创建 工程结构,然后根据命令行提示进行选择.

What platform do you want to use?? [ iOS / macOS ]。~》 iOS

What language do you want to use?? [ Swift / ObjC ]。~》Objc

Would you like to include a demo application with your library? [ Yes / No ] ~>Yes

Which testing frameworks will you use? [ Specta / Kiwi / None ] ~>None

Would you like to do view based testing? [ Yes / No ]. ~>no

What is your class prefix? ~> 个人需求随便

创建到此结束.

2:目录结构等说明

Classes为sdk代码文件夹.

Assets为图片文件夹

对应工程

sdk的说明和引用三方等配置在podspec中

主要如下:

Pod::Spec.new do |s|
  s.name             = 'thridsdk'
  s.version          = '0.0.1'
  s.summary          = ' thridsdk.'
  s.description      = <<-DESC
                            thridsdk
                       DESC
  s.homepage         = 'sdk说明主页'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '作者' => '作者邮箱' }
  s.source           = { :git => 'git地址', :tag => s.version.to_s }
  s.ios.deployment_target = '11.0'
  s.requires_arc = true
  s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64',
    'GCC_PREPROCESSOR_DEFINITIONS' => 'xxxxxxxx='+s.version.to_s}
  s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  
  s.dependency 'Masonry'
  s.dependency 'Reachability'
  s.dependency "FLAnimatedImage", "~> 1.0"
  s.dependency 'MJExtension'
  s.dependency 'AFNetworking', '~> 3.2.1'
  s.dependency 'FMDB'
  s.dependency 'ReactiveCocoa', '~> 2.5'
  s.resource = ['thridsdk/Assets/Images/**/*.{aac,wav,mp3,png,gif}']
  s.static_framework = true
#  s.source_files = 'thridsdk/Classes/**/*'
  s.ios.vendored_frameworks = 'thridsdk.framework'
end

问题:

building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64

或此类架构问题进行如下设置:

podspec文件中添加

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64'}

s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

还需要在pod的安装目录下设置:

我的目录:/Library/Ruby/Gems/2.6.0/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager

builder.rb

274行:

def ios_build_options

"ARCHS=\'$(ARCHS_STANDARD)\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"

end

和pod_utils下

其中thridsdk为最终上传时的静态库,在pods~》Products目录下,目录下为单一架构framework,提供出去时需要将release-iphoneos (arm64架构),release-iphonesimulator(x86架构)中的对应thridsdk.framework中的二进制文件合并.使用如下命令 在Products文件夹下使用:

lipo -create -output output/thridsdk Release-iphoneos/thridsdk/thridsdk.framework/thridsdk Release-iphonesimulator/thridsdk/thridsdk.framework/thridsdk

可以使用命令 lipo -info thridsdk 输出架构信息,确认架构

然后替换其中一个framework中的同名文件,framework双架构包就完成了.

s.source_files = 'thridsdk/Classes/**/* 为开发时设置,可以看到源文件

s.ios.vendored_frameworks = 'thridsdk.framework' 上传时设置,只暴露头文件,删除thridsdk/classes文件夹.

使用下面命令验证sdk是否可以上传pod

pod lib lint thridsdk.podspec --use-libraries --allow-warnings

如果通过

在上传的的仓库中打个和版本号相同的tag

然后就可以上传pod了,用如下命令

pod trunk push thridsdk.podspec --allow-warnings

其中有个在sdk内部获取sdk版本号的需求,实现如下:

在podspec文件中设置 宏定义,将版本号设置到宏里

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64',

'GCC_PREPROCESSOR_DEFINITIONS' => 'thridsdk_version='+s.version.to_s}

注意,多个设置需要在一个s.pod_target_xcconfig =中设置,不然会被覆盖

然后执行pod install,pod会在sdk的targets下 build settings ~》Preprocessor Macros 中设置thridsdk_version宏

宏值取用的时候不是字符串类型需要转化,转化如下:

NSString *sdk_version = [NSString stringWithFormat:@"%@",@OS_STRINGIFY(thridsdk_version)];

直接使用会出现错误:

Invalid suffix '.x' on floating constant 或者 Use of undeclared Identifier 'xxxxxx' 或其他@符号什么乱七八糟的错误.

到此结束

相关推荐
wakangda1 小时前
React Native 集成 iOS 原生功能
react native·ios·cocoa
crasowas21 小时前
iOS - 超好用的隐私清单修复脚本(持续更新)
ios·app store
ii_best1 天前
ios按键精灵脚本开发:ios悬浮窗命令
ios
Code&Ocean1 天前
iOS从Matter的设备认证证书中获取VID和PID
ios·matter·chip
/**书香门第*/1 天前
Laya ios接入goole广告,开始接入 2
ios
恋猫de小郭2 天前
什么?Flutter 可能会被 SwiftUI/ArkUI 化?全新的 Flutter Roadmap
flutter·ios·swiftui
网安墨雨2 天前
iOS应用网络安全之HTTPS
web安全·ios·https
福大大架构师每日一题2 天前
37.1 prometheus管理接口源码讲解
ios·iphone·prometheus
BangRaJun3 天前
LNCollectionView-替换幂率流体
算法·ios·设计
刘小哈哈哈3 天前
iOS 多个输入框弹出键盘处理
macos·ios·cocoa