一 安裝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文件配置
- 首頁需要一個git倉庫用來存放Cer證書
- 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證書自動管理修改為手段管理,就可以解決此問題割岛。