SDK Framework創(chuàng)建 CocoaPods 提交

前言:
公司常需要提供源碼給客戶喳张,但是又有部分源碼是不想給的,所以岂丘,打包成靜態(tài)庫(kù)是一個(gè)不錯(cuò)的選擇陵究,至于是.a還是.framework,看個(gè)人選擇,如果頭文件比較多的元潘,我還是喜歡.framework,簡(jiǎn)潔畔乙,頭文件收藏得深,本文章只是記錄一下開發(fā)流程以供以后翻看翩概,不足之處牲距,請(qǐng)見諒,斧正钥庇。


說(shuō)明:創(chuàng)建Framework的方法一般有兩種牍鞠,一個(gè)是xcode創(chuàng)建,一個(gè)是cocoaPods創(chuàng)建评姨,因?yàn)閯?chuàng)建后难述,需要將它發(fā)布到Pods上給人使用的,公司有部分代碼需要隱私吐句,所以我選擇了用xcode創(chuàng)建了Framework后build出需要版本胁后,再發(fā)布Pods上,但是如果代碼不需要保密嗦枢,可以直接用cocoaPods創(chuàng)建攀芯,這樣子會(huì)省很多事情,利用需要用到cocoaPods管理的第三方框架等


1文虏、創(chuàng)建Framework侣诺,添加一個(gè)簡(jiǎn)單的打印類

創(chuàng)建Framework

創(chuàng)建Framework

添加打印類
添加打印類

2殖演、編輯、打包SDK年鸳,千萬(wàn)切記要General的Deployment Target選擇支持的系統(tǒng)版本趴久,盡量選擇到最舊的8.0,這個(gè)沒有選擇的話搔确,后面會(huì)影響很大

編譯出真機(jī)和虛擬機(jī)使用的.framework彼棍,這里可以選擇debug或者Release

編譯framework

合并出一個(gè)兼容虛擬機(jī)和真機(jī)使用的.framework,特別說(shuō)明一下妥箕,framework和a庫(kù)有點(diǎn)區(qū)別滥酥,合并的文件是.framework里邊的紅色框住的這個(gè)文件,這個(gè)很重要

framework

合并命令:lipo -create 真機(jī)編輯文件路徑 虛擬機(jī)編譯文件路徑 -output 合并后存放文件的路徑

合并后的framework


至此畦幢,已經(jīng)Framework就算完成了坎吻,正如上面所說(shuō),我們需要的是提供包給別人用的宇葱,所以接下來(lái)是如何將SDK放到Pods上面去


3瘦真、將Framework提交到github上

說(shuō)明:因?yàn)镻ods默認(rèn)是基于git的代碼管理,所以要將SDK丟到Pods上去黍瞧,首先需要先放到git上诸尽。以下操作都是默認(rèn)你已經(jīng)有了github的賬號(hào)了的

  • 首先,在git上創(chuàng)建一個(gè)空的新項(xiàng)目印颤,特別注意您机,下面的初始化盡量、最好勾選上年局,還有那個(gè)License际看,也選擇上,后面提交會(huì)用到


    創(chuàng)建項(xiàng)目
  • 然后將該項(xiàng)目克隆到本地矢否,我為了方便查找仲闽,直接放到了桌面

git clone https://github.com/p****/C*******FrameworkTest.git
本地項(xiàng)目
  • 將上面弄好的SDK放到該項(xiàng)目中,并提交


    導(dǎo)入SDK
cd 到.git倉(cāng)庫(kù)的同級(jí)目錄
git add .
git commit -m "注釋說(shuō)明comment log"
git push
git tag 1.0.1
git push --tags
  • 成功后會(huì)在終端見到一下內(nèi)容僵朗,github的工作就差不多了赖欣,現(xiàn)在到Pods了
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/phyky/CocoaPodsFrameworkTest.git
 * [new tag]         1.0.1 -> 1.0.1

  • 注冊(cè)trunk(郵箱和用戶名),通過(guò)會(huì)收到【Please verify the session by clicking the link in the verification email that has been sent to 26******90@qq.com
pod trunk register 26******90@qq.com phyky --verbose
  • 去郵箱驗(yàn)證验庙,將圖中的紅框連接拷到瀏覽器打開顶吮,完成驗(yàn)證


    驗(yàn)證
  • 查看注冊(cè)信息
pod trunk me
- Name:     phyky
- Email:    26******90@qq.com
- Since:    September 10th, 02:02
- Pods:     None
- Sessions:
- September 10th, 02:02 - January 16th, 2019 02:05. IP:
  183.62.48.226
- September 10th, 02:29 - January 16th, 2019 02:29. IP:
  183.62.48.226
  • 創(chuàng)建.spec文件,該文件主要是配置一些項(xiàng)目到Pods的參數(shù),極為重要粪薛。
pod trunk push ./PHYFrameworkTest.podspec
.spec文件
  • 配置.spec文件云矫,部分重要的參數(shù)我標(biāo)了一下注釋,但是里邊的很多參數(shù)我沒有使用汗菜,因?yàn)檫@個(gè)SDK是很簡(jiǎn)單的让禀,而且沒有涉及到png和xib,具體參數(shù)使用陨界,可另行查閱
#
#  Be sure to run `pod spec lint PHYFrameworkTest.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "PHYFrameworkTest"
  s.version      = "1.0.1" //切記要和Git提交的版本號(hào)一致
  s.summary      = "Test for PHYFrameworkTest."

  # This description is used to generate tags and improve search results.
  #   * Think: What does it do? Why did you write it? What is the focus?
  #   * Try to keep it short, snappy and to the point.
  #   * Write the description between the DESC delimiters below.
  #   * Finally, don't worry about the indent, CocoaPods strips it!
  s.description  = <<-DESC
  只是測(cè)試一下巡揍,信不信由你(just for test,no content)
                   DESC//這里的描述必須比上面的summary長(zhǎng),否則報(bào)警告

  s.homepage     = "https://github.com/phyky/CocoaPodsFrameworkTest.git"http://填寫地址
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  #s.license      = "MIT (example)"
  //特別重要菌瘪,這就是上面提到的新建Git項(xiàng)目的時(shí)候腮敌,初始化需要選擇的LICENSE,沒有這個(gè)提交會(huì)報(bào)錯(cuò)
  s.license      = { :type => "MIT", :file => "LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "" => "" }
  # Or just: s.author    = ""
  # s.authors            = { "" => "" }
  # s.social_media_url   = "http://twitter.com/"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  # s.platform     = :ios
  //平臺(tái)俏扩、系統(tǒng)版本必填糜工,否則會(huì)報(bào)osx相關(guān)的警告,也是提交不了录淡,前面打包Framework的時(shí)候提到的重要性
   s.platform     = :ios, "8.0"

  #  When using multiple platforms
  # s.ios.deployment_target = "8.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://github.com/phyky/CocoaPodsFrameworkTest.git", :tag => "#{s.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #
//特別重要捌木,這里邊的.h或者.m文件不能只是配到.framework,否則找不到,報(bào)錯(cuò)
  s.source_files  = "lib/PHYFrameworkTest.framework/Headers/*.{h}"
  #s.exclude_files = "Classes/Exclude"

  # s.public_header_files = "Classes/**/*.h"
//特別重要嫉戚,這里必須配置刨裆,否則上傳成功,找不到.framework,只有頭文件
  s.vendored_frameworks = 'lib/PHYFrameworkTest.framework'

  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #
//如果有用到資源的彬檀,路徑配置參考上面的s.source_files
  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  # s.framework  = "SomeFramework"
  # s.frameworks = "UIKit", "Foundation"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  # s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # s.dependency "JSONKit", "~> 1.4"

end

  • 校驗(yàn)spec文件是否正確帆啃,這步可能會(huì)拋出很多警告或者錯(cuò)誤,對(duì)照著去修改就行
pod spec lint
  • 檢驗(yàn)通過(guò)窍帝,提示以下
 -> PHYFrameworkTest (1.0.1)
Analyzed 1 podspec.
PHYFrameworkTest.podspec passed validation.
  • 提交到Pods努潘,成功會(huì)有以下的提示
pod trunk push ./PHYFrameworkTest.podspec
Congrats
PHYFrameworkTest (1.0.1) successfully published
September 10th, 03:23
https://cocoapods.org/pods/PHYFrameworkTest
Tell your friends!

進(jìn)行到這里,SDK就算是完整創(chuàng)建并提交完了坤学,迫不及待去【pod search PHYFrameworkTest】一下疯坤,發(fā)現(xiàn)并沒有找到,更新一下pod拥峦,刪除掉pod本地的搜索緩存【~/Library/Caches/CocoaPods】贴膘,就會(huì)搜索到了。以下是最后的成果


Framework測(cè)試
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末略号,一起剝皮案震驚了整個(gè)濱河市刑峡,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌玄柠,老刑警劉巖突梦,帶你破解...
    沈念sama閱讀 216,496評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異羽利,居然都是意外死亡宫患,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門这弧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)娃闲,“玉大人虚汛,你說(shuō)我怎么就攤上這事』拾铮” “怎么了卷哩?”我有些...
    開封第一講書人閱讀 162,632評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)属拾。 經(jīng)常有香客問(wèn)我将谊,道長(zhǎng),這世上最難降的妖魔是什么渐白? 我笑而不...
    開封第一講書人閱讀 58,180評(píng)論 1 292
  • 正文 為了忘掉前任尊浓,我火速辦了婚禮,結(jié)果婚禮上纯衍,老公的妹妹穿的比我還像新娘栋齿。我一直安慰自己,他們只是感情好托酸,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評(píng)論 6 388
  • 文/花漫 我一把揭開白布褒颈。 她就那樣靜靜地躺著,像睡著了一般励堡。 火紅的嫁衣襯著肌膚如雪谷丸。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,165評(píng)論 1 299
  • 那天应结,我揣著相機(jī)與錄音刨疼,去河邊找鬼。 笑死鹅龄,一個(gè)胖子當(dāng)著我的面吹牛揩慕,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播扮休,決...
    沈念sama閱讀 40,052評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼迎卤,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了玷坠?” 一聲冷哼從身側(cè)響起蜗搔,我...
    開封第一講書人閱讀 38,910評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎八堡,沒想到半個(gè)月后樟凄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,324評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡兄渺,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評(píng)論 2 332
  • 正文 我和宋清朗相戀三年缝龄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,711評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡叔壤,死狀恐怖瞎饲,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情百新,我是刑警寧澤企软,帶...
    沈念sama閱讀 35,424評(píng)論 5 343
  • 正文 年R本政府宣布,位于F島的核電站饭望,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏形庭。R本人自食惡果不足惜铅辞,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評(píng)論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望萨醒。 院中可真熱鬧斟珊,春花似錦、人聲如沸富纸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)晓褪。三九已至堵漱,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間涣仿,已是汗流浹背勤庐。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工蔬捷, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留诈乒,地道東北人容贝。 一個(gè)月前我還...
    沈念sama閱讀 47,722評(píng)論 2 368
  • 正文 我出身青樓酥郭,卻偏偏與公主長(zhǎng)得像滩报,于是被迫代替她去往敵國(guó)和親猴娩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子欺殿,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容