当前位置:   article > 正文

iOS pod sdk开发到发布,记录

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中

主要如下:

  1. Pod::Spec.new do |s|
  2. s.name = 'thridsdk'
  3. s.version = '0.0.1'
  4. s.summary = ' thridsdk.'
  5. s.description = <<-DESC
  6. thridsdk
  7. DESC
  8. s.homepage = 'sdk说明主页'
  9. s.license = { :type => 'MIT', :file => 'LICENSE' }
  10. s.author = { '作者' => '作者邮箱' }
  11. s.source = { :git => 'git地址', :tag => s.version.to_s }
  12. s.ios.deployment_target = '11.0'
  13. s.requires_arc = true
  14. s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64',
  15. 'GCC_PREPROCESSOR_DEFINITIONS' => 'xxxxxxxx='+s.version.to_s}
  16. s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  17. s.dependency 'Masonry'
  18. s.dependency 'Reachability'
  19. s.dependency "FLAnimatedImage", "~> 1.0"
  20. s.dependency 'MJExtension'
  21. s.dependency 'AFNetworking', '~> 3.2.1'
  22. s.dependency 'FMDB'
  23. s.dependency 'ReactiveCocoa', '~> 2.5'
  24. s.resource = ['thridsdk/Assets/Images/**/*.{aac,wav,mp3,png,gif}']
  25. s.static_framework = true
  26. # s.source_files = 'thridsdk/Classes/**/*'
  27. s.ios.vendored_frameworks = 'thridsdk.framework'
  28. 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' 或其他@符号什么乱七八糟的错误.

到此结束

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/数据灵魂/article/detail/60806
推荐阅读
相关标签
  

闽ICP备14008679号