让CocoaPods组件支持Carthage打包
栏目: Objective-C · 发布时间: 6年前
内容简介:虽说 CocoaPods 有要让组件支持 Carthage ,工程里只需要有一个对于剩下的
虽说 CocoaPods 有 cocoapods-packager 这个插件可以生成二进制版本,但这个库的维护者似乎并不活跃,很多 issue 和 pr 过了一两年还堆积着没处理。于是我决定试试 Carthage ,不过不利用 Cartfile 生成依赖,还是用的 CocoaPods 那一套。
要让组件支持 Carthage ,工程里只需要有一个 shared framework target
即可。针对 CocoaPods 生成的工程,我们先在 Podfile 里面设置 use_frameworks!
,来满足 framework target
。
对于剩下的 share
部分,可以用 Add share schemes for development pods
这个 pr 里面的方法解决:
install! 'cocoapods', :share_schemes_for_development_pods => false
不过上面的那种方式把所有的 development pods
对应的 target 都 share 了,这里我们可以这样设置特定的 development pods
:
install! 'cocoapods', :share_schemes_for_development_pods => ['PodA']
在 CocoaPods 1.4.0 版本中, share_schemes_for_development_pods
默认是 false 的,所以需要手动在 Podfile 里面去添加这一句。
最后执行一下 pod install
,然后再执行 carthage build --no-skip-current --platform ios
就可以打出 ios 版本的 dynamic framework 了。想利用 Carthage 打出 static framework 的可以查看 Build static frameworks to speed up your app’s launch times
。
再进一步,我们可以把这个默认设置写入团队专有的 CocoaPods 插件中,比如 cocoapods-xxx-plugin
:
Pod::HooksManager.register('cocoapods-xxx-plugin', :pre_install) do |context, _|
first_target_definition = context.podfile.target_definition_list.select{ |d| d.name != 'Pods' }.first
development_pod = first_target_definition.name.split('_').first unless first_target_definition.nil?
Pod::UI.section("Auto set share scheme for development pod: \'#{development_pod}\'") do
# carthage 需要 shared scheme 构建 framework
context.podfile.install!('cocoapods', :share_schemes_for_development_pods => [development_pod])
end unless development_pod.nil?
end
在 Podfile 添加以下代码,让插件生效:
plugin 'cocoapods-xxx-plugin'
好处就是以后有更多相似配置的话都可以通过更改这个插件解决,而不用每次都去 Podfile 里面改 pre_install
。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- react无状态组件方式实现无需打包的npm包
- 【前端打包部署】谈一谈我在SPA项目打包=>部署的处理
- Maven多模块项目打包前的一些注意事项(打包失败)
- tar打包如何不打包某一个文件夹(排除某些文件夹)
- iOS新手用swift写一个macos打包工具 一键打包到指定位置
- Android应用签名打包
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Ordering Disorder
Khoi Vinh / New Riders Press / 2010-12-03 / USD 29.99
The grid has long been an invaluable tool for creating order out of chaos for designers of all kinds—from city planners to architects to typesetters and graphic artists. In recent years, web designers......一起来看看 《Ordering Disorder》 这本书的介绍吧!