本文介绍: s.ios.vendored_frameworks = ‘thridsdk.framework’ 上传时设置,只暴露头文件,删除thridsdk/classes文件夹.我的目录:/Library/Ruby/Gems/2.6.0/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager。s.source_files = ‘thridsdk/Classes/**/* 为开发时设置,可以看到源文件。在podspec文件中设置 宏定义,将版本号设置到宏里。

本文章记录从开发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’ 或其他@符号什么乱七八糟的错误.

到此结束

原文地址:https://blog.csdn.net/ant1239/article/details/135976089

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_66515.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注