iOS Fastlane 使用文檔

一 安裝fastlane

sudo gem install fastlane --verbose
如果安裝失數牖:
ERROR:  While executing gem ... (TypeError)
    no implicit conversion of nil into String
進行更新gem:    
sudo gem update --system
安裝成功:
?  1.0 fastlane -v
Ignoring bigdecimal-1.3.5 because its extensions are not built.  Try: gem pristine bigdecimal --version 1.3.5
fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.112.0/bin/fastlane
-----------------------------
[?] ?? Ignoring io-console-0.4.6 because its extensions are not built.  Try: gem pristine io-console --version 0.4.6
Ignoring nokogiri-1.8.4 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.4
Ignoring psych-3.0.2 because its extensions are not built.  Try: gem pristine psych --version 3.0.2
Ignoring sqlite3-1.3.13 because its extensions are not built.  Try: gem pristine sqlite3 --version 1.3.13
[?] ?? 
fastlane 2.112.0

二 割粮、項目初始化

fastlane init

**************** % fastlane init

[?] ?? 
[?] Looking for iOS and Android projects in current directory...
[11:14:47]: Created new folder './fastlane'.
[11:14:47]: Detected an iOS/macOS project in the current directory: '調(diào)機軟件.xcworkspace'
[11:14:47]: -----------------------------
[11:14:47]: --- Welcome to fastlane ?? ---
[11:14:47]: -----------------------------
[11:14:47]: fastlane can help you with all kinds of automation for your mobile app
[11:14:47]: We recommend automating one task first, and then gradually automating more over time
[11:14:47]: What would you like to use fastlane for?
1. ??  Automate screenshots
2. ????  Automate beta distribution to TestFlight
3. ??  Automate App Store distribution
4. ??  Manual setup - manually setup your project to automate your tasks
1. 自動截屏并鸵。這個功能能幫我們自動截取APP中的截圖苇倡,并添加手機邊框(如果需要的話)拳球,我們這里不選擇這個選項审姓,因為我們的項目已經(jīng)有圖片了,不需要這里截屏祝峻。
2. 自動發(fā)布beta版本用于TestFlight魔吐,如果大家有對TestFlight不了解的,可以參考王巍寫的這篇文章
3. 自動的App Store發(fā)布包莱找。我們的目標是要提交審核到APP Store酬姆,按道理應該選這個,但這里我們先不選奥溺,因為選擇了以后會需要輸入用戶名密碼辞色,以及下載meta信息,需要花費一定時間谚赎,這些數(shù)據(jù)我們可以后期進行配置淫僻。
4. 手動設置

直接選擇第4個對其進行手動配置后進入:

[15:17:15]: ------------------------------------------------------------
[15:17:15]: --- Setting up fastlane so you can manually configure it ---
[15:17:15]: ------------------------------------------------------------
[15:17:15]: Installing dependencies for you...
[15:17:15]: $ bundle update

其他命令:

fastlane actions:      列出所有可用fastlane活動
fastlane action [action_name]:   顯示一個更詳細的活動描述
fastlane lanes:      列出所有可用lanes (有描述)
fastlane list:       列出所有可用lanes (沒有描述)
fastlane new_action:     在fastlane創(chuàng)建一個活動(集成)

三、對fastlane 文件的認識:

現(xiàn)在對Appfile壶唤,F(xiàn)astfile饶囚,Gemfile厘唾,Deliverfile文件說明如下:

Appfile: 存儲有關開發(fā)者賬號相關信息
Fastfile: 核心文件擂啥,用于命令行調(diào)用和處理具體的流程遗锣,lane相對于一個action方法或函數(shù) 
Gemfile 類似于cocopods 的Podfile文件
.env 配置環(huán)境變量(在fastlane init進行初始化后并不會自動生成,如果需要可以自己創(chuàng)建
Deliverfile: deliver工具的配置文件,上傳截圖蘋果和后臺一些app信息  (默認不生成躲撰,需要sudo gem install deliver安裝)然后在fastlane 目錄下執(zhí)行deliver init 即可)
要注意的點:
build_app命令等同于gym(別名)
deliver 命令相當于upload_to_app_store(別名)

四针贬、添加插件

列出所有的插件

fastlane search_plugins

搜索指定名稱的插件

fastlane search_plugins [query]

添加插件

fastlane add_plugin [name]

安裝插件

fastlane install_plugins
添加蒲公英插件
fastlane add_plugin pgyer
fastlane add_plugin versioning

添加match全家桶

fastlane match init

五、配置相關文件信息

配置主文件:Fastfile
配置證書的存放路徑

Appfile文件代碼如下:

app_identifier("com.****.****") # The bundle identifier of your app
apple_id("********@qq.com") # Your Apple email address

itc_team_id("*******") # App Store Connect Team ID
team_id("*******") # Developer Portal Team ID

# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile
#--發(fā)布蒲公英上的版本配置

for_lane :pgy do
  app_identifier "com.*******.cn" # The bundle identifier of your app
  apple_id "*************@163.com" # Your Apple email address 
end

Fastfile文件文件代碼如下:

定義打包平臺
default_platform :ios

platform :ios do
  before_all do
    git_pull
    last_git_commit
    sh "rm -f ./Podfile.lock"
       cocoapods(use_bundle_exec: false)

end
運行所有的測試
lane :test do
   scan
end
提交一個新的Beta版本
確保配置文件是最新的
lane :beta do
gym 
pilot 
end
將新版本部署到應用程序商店
lane :release do
gym 
deliver(force: true) 
end
以下是發(fā)布版本的配置
lane :pgy do
    
sigh(
        app_identifier: "com.zidongdabao.cn" #項目的bundle identifler
    )
開始打包
# 定義打包平臺
default_platform :ios

platform :ios do
  before_all do
    git_pull
    last_git_commit
    sh "rm -f ./Podfile.lock"
       cocoapods(use_bundle_exec: false)

end

# 運行所有的測試
  lane :test do
    scan
end

# 提交一個新的Beta版本
# 確保配置文件是最新的
lane :beta do
   
    gym 
    pilot 
end

# 將新版本部署到應用程序商店
lane :release do
    gym(
        clean: true,
        output_directory: './fastlane/build',
       output_name:"xxxx.ipa",
       configuration: 'Release',
       export_options: {
             method: 'app-store',#正式包
             provisioningProfiles: {
                     "your_identifier" => "xxxx" #測試打包描述文件
            },
       }
    )
deliver(force: true)
end

# 以下是發(fā)布版本的配置

lane :pgy do
    
sigh(
        app_identifier: "com.zidongdabao.cn" #項目的bundle identifler
    )

# 開始打包    
gym(
     
    scheme: “Fastlane--Packaging”, #指定項目的scheme名稱
    configuration: "Release", # 指定打包方式拢蛋,Release 或者 Debug
    silent: true, # 隱藏沒有必要的信息
    clean: true, # 是否清空以前的編譯信息 true:是
    workspace: "Fastlane--Packaging.xcworkspace",
    include_bitcode: false, #項目中的bitcode 設置
    output_directory: './pgy', # 指定輸出文件夾
    output_name: "Fastlane--Packaging.ipa", #輸出的ipa名稱
    export_xcargs: "-allowProvisioningUpdates”, #忽略文件
    )

# 開始上傳蒲公英
pgyer(api_key: "1303c11160b475cc56b9d5df820a17ed", user_key: "dd705842c35567b3f2620e6a047024f0")

end

end
4.在終端執(zhí)行自動打包

在終端輸入

fastlane ios
fatlane --命令說明

* scan -- 自動運行測試工具桦他,并且可以生成漂亮的HTML報告

  • cert -- 自動創(chuàng)建管理iOS代碼簽名證書

* sigh -- 一聲嘆息啊,這么多年和Provisioning Profile戰(zhàn)斗過無數(shù)次谆棱】煅梗總是有這樣那樣的問題導致配置文件過期或者失效。sigh是用來創(chuàng)建垃瞧、更新蔫劣、下載、 修復Provisioning Profile的工具个从。

  • pem -- 自動生成脉幢、更新推送配置文件

* match -- 一個新的證書和配置文件管理工具。我會另寫一篇文章專門介紹這個工具嗦锐。他會所有需要用到的證書傳到git私有庫上嫌松,任何需要配置的機器直接用match同步回來就不用管證書問題了,小團隊福音稗任邸豆瘫! * gym -- Fastlane家族的自動化編譯工具,和其他工具配合的非常默契

  • produce -- 如果你的產(chǎn)品還沒在iTunes Connect(iTC)或者Apple Developer Center(ADC)建立菊值,produce可以自動幫你完成這些工作

* deliver -- 自動上傳截圖,APP的元數(shù)據(jù)育灸,二進制(ipa)文件到iTunes Connect

  • pilot -- 管理TestFlight的測試用戶腻窒,上傳二進制文件

六、遇到問題

出現(xiàn)錯誤:

[17:13:49]: ? ** ARCHIVE SUCCEEDED **
[17:13:49]: 
[17:13:49]: ??  Check out the few lines of raw `xcodebuild` output above for potential hints on how to solve this error
[17:13:49]: ??  For the complete and more detailed error log, check the full log at:
[17:13:49]: ??  /Users/liujingxu/Library/Logs/gym/M-Pay-M-Pay.log
[17:13:49]: 
[17:13:49]: Looks like fastlane ran into a build/archive error with your project
[17:13:49]: It's hard to tell what's causing the error, so we wrote some guides on how
[17:13:49]: to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[17:13:49]: Before submitting an issue on GitHub, please follow the guide above and make
[17:13:49]: sure your project is set up correctly.
[17:13:49]: fastlane uses `xcodebuild` commands to generate your binary, you can see the
[17:13:49]: the full commands printed out in yellow in the above log.
[17:13:49]: Make sure to inspect the output above, as usually you'll find more error information there
[17:13:49]: 
[17:13:49]: Looks like no provisioning profile mapping was provided
[17:13:49]: Please check the complete output, in particular the very top
[17:13:49]: and see if you can find more information. You can also run fastlane
[17:13:49]: with the `--verbose` flag.
[17:13:49]: Alternatively you can provide the provisioning profile mapping manually
[17:13:49]: https://docs.fastlane.tools/codesigning/xcode-project/#xcode-9-and-up
+------------------+---------------+
|           Lane Context           |
+------------------+---------------+
| DEFAULT_PLATFORM | ios           |
| PLATFORM_NAME    | ios           |
| LANE_NAME        | ios adhoc_pgy |
| BUILD_NUMBER     | 2             |
+------------------+---------------+
[17:13:49]: Error packaging up the application

+------+------------------------+-------------+
|              fastlane summary               |
+------+------------------------+-------------+
| Step | Action                 | Time (in s) |
+------+------------------------+-------------+
| 1    | default_platform       | 0           |
| 2    | cocoapods              | 3           |
| 3    | increment_build_numbe  | 1           |
|      | r                      |             |
| ??   | build_app              | 84          |
+------+------------------------+-------------+

[17:13:49]: fastlane finished with errors

[!] Error packaging up the application

match文件配置

  1. 首頁需要一個git倉庫用來存放Cer證書
  2. git 倉庫需要添加ssh公鑰
生產(chǎn)密鑰:ssh-keygen 
查看密鑰:cat ~/.ssh/id_rsa.pub

2磅崭、錯誤信息

[16:19:23]: URL to the git repo containing all the certificates: https://gitee.com/mxlj/M-Pay-Cer.git
[16:19:33]: Cloning remote git repo...
[16:19:33]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
Cloning into '/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2'...
fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
[16:19:34]: Exit status: 128
[16:19:34]: Error cloning certificates repo, please make sure you have read access to the repository you want to use
[16:19:34]: Run the following command manually to make sure you're properly authenticated:
[16:19:34]: $ git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2

[!] Error cloning certificates git repo, please make sure you have access to the repository - see instructions above
解決方法:

注:出現(xiàn)這個問題是因為mac git終端沒有讀寫的權限儿子,問題。
未找到修改權限的方法來解決此問題砸喻,所有使用下面的方面來解決柔逼。

運行:

git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/xc/bzrxbntn1fq_fw53ks0_jbzc0000gn/T/d20190409-13848-156jw68

修改Fastlane文件的scheme:為項目名稱

報satus 70錯誤

** EXPORT FAILED **
[17:28:29]: Exit status: 70

解決辦法:
把xcode證書自動管理修改為手段管理,就可以解決此問題割岛。

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末愉适,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子癣漆,更是在濱河造成了極大的恐慌维咸,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,865評論 6 518
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異癌蓖,居然都是意外死亡瞬哼,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,296評論 3 399
  • 文/潘曉璐 我一進店門租副,熙熙樓的掌柜王于貴愁眉苦臉地迎上來坐慰,“玉大人,你說我怎么就攤上這事用僧〗嵴停” “怎么了?”我有些...
    開封第一講書人閱讀 169,631評論 0 364
  • 文/不壞的土叔 我叫張陵永毅,是天一觀的道長把跨。 經(jīng)常有香客問我,道長沼死,這世上最難降的妖魔是什么着逐? 我笑而不...
    開封第一講書人閱讀 60,199評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮意蛀,結(jié)果婚禮上耸别,老公的妹妹穿的比我還像新娘。我一直安慰自己县钥,他們只是感情好秀姐,可當我...
    茶點故事閱讀 69,196評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著若贮,像睡著了一般省有。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上谴麦,一...
    開封第一講書人閱讀 52,793評論 1 314
  • 那天蠢沿,我揣著相機與錄音,去河邊找鬼匾效。 笑死舷蟀,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的面哼。 我是一名探鬼主播野宜,決...
    沈念sama閱讀 41,221評論 3 423
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼魔策!你這毒婦竟也來了匈子?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,174評論 0 277
  • 序言:老撾萬榮一對情侶失蹤代乃,失蹤者是張志新(化名)和其女友劉穎旬牲,沒想到半個月后仿粹,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,699評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡原茅,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,770評論 3 343
  • 正文 我和宋清朗相戀三年吭历,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片擂橘。...
    茶點故事閱讀 40,918評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡晌区,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出通贞,到底是詐尸還是另有隱情朗若,我是刑警寧澤,帶...
    沈念sama閱讀 36,573評論 5 351
  • 正文 年R本政府宣布昌罩,位于F島的核電站哭懈,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏茎用。R本人自食惡果不足惜遣总,卻給世界環(huán)境...
    茶點故事閱讀 42,255評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望轨功。 院中可真熱鬧旭斥,春花似錦、人聲如沸古涧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,749評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽羡滑。三九已至菇爪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間柒昏,已是汗流浹背娄帖。 一陣腳步聲響...
    開封第一講書人閱讀 33,862評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留昙楚,地道東北人。 一個月前我還...
    沈念sama閱讀 49,364評論 3 379
  • 正文 我出身青樓诈嘿,卻偏偏與公主長得像堪旧,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子奖亚,可洞房花燭夜當晚...
    茶點故事閱讀 45,926評論 2 361