Cocoapod Package命令打包问题汇总

Cocoapod Package命令打包问题汇总

Xcode12 的 arm64 冲突适配

如果是没有修改过这块,仅仅使用ARCHS_STANDARD架构有可能还是无法成功出包的,原因在于,Xcode12 开始增加了 M1 设备支持,模拟器和真机同时包含arm64架构,导致了架构冲突。

对于这一点,参照参考 2能修复Xcode12之后arm64冲突的问题,修改方式为修改cocoapods-packager的源码中的pod_utils.rb文件

unless static_installer.nil?
  static_installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
      config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO'
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' //在这里添加
    end
  end
  static_installer.pods_project.save
end

或者在podspec文件增加排除arm64的代码

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

Xcode14 armv7架构报错

这是因为Xcode14目前最低支持版本已经提到了 iOS11所以移除了armv7, armv7s, and i386 参考

error: The armv7 architecture is deprecated. You should update your ARCHS build setting to remove the armv7 architecture. (in target 'Pods-packager' from project 'Pods')

解决方法:

修改cocoapod packager源文件中的builder.rb的ARCHS为$(ARCHS_STANDARD)就可以修复Xcode14打已经被移除的armv7(s)失败的问题

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

Xcode14打出来的包Xcode13以下报错误_objc_msgSend$xxx

Undefined symbol: _objc_msgSend$stringByTrimmingCharactersInSet:
Undefined symbol: _objc_msgSendSsize
Undefined symbol: _objc_msgSend$drawInRect:

这是因为Xcode14会优化减少代码的二进制,实质是通过 objc_msgSend,提取为一个 helper func(selector stub),通过这一优化减少了 2%的二进制大小,并且这一优化在 Xcode14 自动启用。所以就导致xcode13无法理解从而报错。

网上的大家说的修改OTHER_CFLAGS,添加-fno-objc-msgsend-selector-stubs参数,关闭这项优化。这个原理是对的,但是实际验证下来都无效,packager打出来的 sdk Xcode13 还是无法理解

结合这里和 参考1,基本确定主要原因是 packager 就没有使用那些参数去打包,而是用自己的 build options,所以在 pod spec 里配置的都是无法影响打包结果

因此需要还是需要修改cocoapod packager的源文件,所以要在builder.rbios_build_options方法里追加-fno-objc-msgsend-selector-stubs

def ios_build_options
   "ARCHS=\'$(ARCHS_STANDARD)\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments -fno-objc-msgsend-selector-stubs\'"
end

Xcode 14打包签名报错

error: Signing for "xxx-xxx" requires a development team. Select a development team in the Signing & Capabilities editor. (in target 'xxx-xxx' from project 'Pods')

解决办法也很简单就是给pod库里的bundle资源文件设置bundle identifierteam,让它和主工程一样就可以了。但pod里的配置都是自动生成的在执行pod install之后我们的配置就会消失,所以这时候改packager的源文件比较牢靠。参考这里可以把项目里的签名设置为空,所以我们修改pod_utils文件就可以了

 unless static_installer.nil?
      static_installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
          config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO'
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
          #插入这里
          config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
          config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
          config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
        end
      end
      static_installer.pods_project.save
end

至此packager上打包失败能出现的问题我们都可以解决了,可以愉快的写代码了!

参考

https://www.jianshu.com/p/cadf4ec9102b

https://www.jianshu.com/p/cc616fa037b2

你可能感兴趣的:(Cocoapod Package命令打包问题汇总)