fastlane運行所需要的環境:
- OS X 10.9以上
- Ruby 2.0 以上
- Xcode
- 擁有一個開發者賬號
因為fastlane其實是一個Ruby腳本的集合,你必須安裝正確的Ruby版本。可用一下命令確認
安裝
1、ruby -v
查看ruby版本
2、然后檢查Xcode命令行工具(CLT)是否安裝。在終端中輸入命令:
xcode-select --install
如果已經安裝,則會報一下錯誤
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
如果沒安裝,終端會開始安裝CLT。
3、通過rubygem安裝fastlane
sudo gem install fastlane -v 2.57.2 --verbose
初始化
打開終端,cd到你的工程目錄,然后執行fastlane init
運行結果如下
fastlane init
[15:35:29]: Seems like launching fastlane takes a while - please run
[15:35:29]:
[15:35:29]: $ [sudo] gem cleanup
[15:35:29]:
[15:35:29]: to uninstall outdated gems and make fastlane launch faster
[15:35:29]: Alternatively it's recommended to start using a Gemfile to lock your dependencies
[15:35:29]: To get started with a Gemfile, run
[15:35:29]:
[15:35:29]: $ bundle init
[15:35:29]: $ echo 'gem "fastlane"' >> Gemfile
[15:35:29]: $ bundle install
[15:35:29]:
[15:35:29]: After creating the Gemfile and Gemfile.lock, commit those files into version control
[15:35:29]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[15:35:32]: Detected iOS/Mac project in current directory...
[15:35:32]: This setup will help you get up and running in no time.
[15:35:32]: fastlane will check what tools you're already using and set up
[15:35:32]: the tool automatically for you. Have fun!
[15:35:32]: Created new folder './fastlane'.
[15:35:32]: $ xcodebuild -list -project ./JenkinsDemo.xcodeproj
2017-12-07 15:35:33.629 xcodebuild[39937:3765993] [MT] PluginLoading: Required plug-in compatibility UUID DF11C142-1584-4A99-87AC-1925D5F5652A for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/FuzzyAutocomplete.xcplugin' not present in DVTPlugInCompatibilityUUIDs
[15:35:34]: $ xcodebuild -showBuildSettings -scheme JenkinsDemo -project ./JenkinsDemo.xcodeproj
2017-12-07 15:35:34.373 xcodebuild[39940:3766165] [MT] PluginLoading: Required plug-in compatibility UUID DF11C142-1584-4A99-87AC-1925D5F5652A for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/FuzzyAutocomplete.xcplugin' not present in DVTPlugInCompatibilityUUIDs
[15:35:35]: Your Apple ID (e.g. fastlane@krausefx.com): 這里是你的Apple ID
[15:35:49]: Verifying that app is available on the Apple Developer Portal and iTunes Connect...
[15:35:49]: Starting login with user '這里是你的Apple ID'
+----------------+--------------------------------------+
| Detected Values |
+----------------+--------------------------------------+
| Apple ID | 這里是你的Apple ID |
| App Name | JenkinsDemo |
| App Identifier | com.jenkin.Debug |
| Project | /Users/xyj/Desktop/test/JenkinsDemo |
| | .xcodeproj |
+----------------+--------------------------------------+
[15:36:00]: Please confirm the above values (y/n)
y
[15:36:11]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
[15:36:11]: Loading up 'deliver', this might take a few seconds
[15:36:11]: Login to iTunes Connect (it_ios@ixinyongjia.com)
[15:36:14]: Login successful
+--------------------------------------+------------------------+
| deliver 2.68.2 Summary |
+--------------------------------------+------------------------+
| run_precheck_before_submit | false |
| screenshots_path | ./fastlane/screenshots |
| metadata_path | ./fastlane/metadata |
| username | 這里是你的Apple ID |
| app_identifier | com.jenkin.Debug |
| edit_live | false |
| platform | ios |
| skip_binary_upload | false |
| skip_screenshots | false |
| skip_metadata | false |
| skip_app_version_update | false |
| force | false |
| submit_for_review | false |
| automatic_release | false |
| dev_portal_team_id | 99WG99HF75 |
| overwrite_screenshots | false |
| precheck_default_rule_level | warn |
| ignore_language_directory_validatio | false |
| n | |
| precheck_include_in_app_purchases | true |
+--------------------------------------+------------------------+
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/description.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/keywords.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/release_notes.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/support_url.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/marketing_url.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/promotional_text.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/name.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/subtitle.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/privacy_url.txt'
[15:36:17]: Writing to './fastlane/metadata/copyright.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_category.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_first_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_second_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_first_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_second_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/trade_name.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/address_line1.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/city_name.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/country.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/postal_code.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/is_displayed_on_app_store.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/first_name.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/last_name.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/phone_number.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/email_address.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/demo_user.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/demo_password.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/notes.txt'
[15:36:17]: Successfully created new configuration files.
[15:36:17]: Downloading all existing screenshots...
[15:36:19]: Successfully downloaded all existing screenshots
[15:36:19]: Successfully created new Deliverfile at path './fastlane/Deliverfile'
[15:36:19]: 'snapshot' not enabled.
[15:36:19]: 'cocoapods' not enabled.
[15:36:19]: 'carthage' not enabled.
[15:36:19]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[15:36:19]: fastlane will collect the number of errors for each action to detect integration issues
[15:36:19]: No sensitive/private information will be uploaded
[15:36:19]: Learn more at https://github.com/fastlane/fastlane#metrics
[15:36:19]: Successfully finished setting up fastlane
上述過程可能要輸密碼,將Apple ID的密碼正確輸入就可以了。
初始化完成之后,工程目錄下就多了個fastlane文件夾,內容如下
這里肯定會被創建的是Appfile和Fastfile。如果Deliverfile,screenshots和metadata目錄沒被創建,可以運行deliver init來創建。
Appfile :用來存儲一些公共信息,比如
app_identifier
、apple_id
、team_id
、itc_team_id
等。Fastfile:用來定義所有的lane任務
一開始的內容如下:
# Customize this file, documentation can be found here:
# https://docs.fastlane.tools/actions/
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command
# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`
# If you want to automatically update fastlane if a new version is available:
# 自動更新fastlane
# update_fastlane
# This is the minimum version number required.
# Update this, if you use features of a newer version
# 需要的fastlane的最小版本,在每次執行之后會檢查是否有新版本,如果有會在最后末尾追加新版本提醒
fastlane_version "2.68.2"
# 默認使用平臺是ios,也就是說可以定義多個平臺
default_platform :ios
# 執行所有的lane語句之前要做的事情,
platform :ios do
before_all do
# 自定義變量
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
# 是否使用cocoapods構建項目
# cocoapods
# carthage
end
# 跑一遍測試
desc "Runs all the tests"
lane :test do
run_tests
end
# 提交一個新的beta版本到 Apple TestFlight
desc "Submit a new Beta Build to Apple TestFlight"
desc "This will also make sure the profile is up to date"
lane :beta do
# match(type: "appstore") # more information: https://codesigning.guide
build_app(scheme: "JenkinsDemo") # more options available
upload_to_testflight
# sh "your_script.sh"
# You can also use other beta testing services here (run `fastlane actions`)
end
# 部署一個新版本到App store
desc "Deploy a new version to the App Store"
lane :release do
# sync_code_signing(type: "appstore")
capture_screenshots
build_app(scheme: "JenkinsDemo") # Build your app - more options available
upload_to_app_store(force: true)
# frame_screenshots
end
# 你也可以定義自己的lane
# You can define as many lanes as you want
# 執行lane之后的回調
after_all do |lane|
# This block is called, only if the executed lane was successful
# slack(
# message: "Successfully deployed new App Update."
# )
end
# 流程異常,結束流程并輸出錯誤信息
error do |lane, exception|
# slack(
# message: exception.message,
# success: false
# )
end
end
# More information about multiple platforms in fastlane: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
# All available actions: https://docs.fastlane.tools/actions
# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://docs.fastlane.tools/#metrics
在 fastlane 這個大家庭中,主要但包括不盡于下列工具:
- scan 自動化測試工具,很好的封裝了 Unit Test
- sigh: 創建、更新、下載和修復 provisioning profiles。
- match 同步團隊每個人的證書和 Provision file 的超贊工具
- cert: 自動創建和維護 iOS 代碼簽名證書。
- gym: 創建和打包 iOS app。
- deliver: 上傳屏幕截圖、元數據和 App 到 App 商店。
- produce: 創建可用于 iTunes Connect 和 Apple Developer Portal 的 iOS app。
- snapshot: 自動將 App屏幕截圖本地化到每種設備上。
- frameit: 將屏幕截圖適配到適當的設備屏幕大小。
- PEM: 自動創建和更新 Push 通知的 profile。
fastlane 實戰
一、打一個測試包,并上傳到蒲公英交付測試.
1、創建一個匹配開發證書的lane
說明:其中一個lane就是一個任務,里面是一個個的action組成的工作流
打開fastlane文件夾下的Fastfile文件(最好用xcode打開)。
創建一個lane:格式如下
desc "匹配開發證書"
lane :matchDev do
match(type: "development", keychain_password: "git")
end
說明:主要用到了match工具,其中type
是指定環境,keychain_password
,服務器鑰匙串密碼,match工具當然不止這些參數,想了解更多參數可以在終端執行fastlane action match
,或者fastlane match --help
來查看文檔。
創建好了,在終端執行如下:
fastlane matchDev
[17:55:34]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[17:55:38]: -------------------------------------------------
[17:55:38]: --- Step: Verifying required fastlane version ---
[17:55:38]: -------------------------------------------------
[17:55:38]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2 ?
[17:55:38]: ------------------------------
[17:55:38]: --- Step: default_platform ---
[17:55:38]: ------------------------------
[17:55:38]: Driving the lane 'ios matchDev' ??
[17:55:38]: -------------------
[17:55:38]: --- Step: match ---
[17:55:38]: -------------------
+-----------------------+------------------------+
| Summary for match 2.68.2 |
+-----------------------+------------------------+
| type | development |
| keychain_password | ******** |
| git_branch | master |
| app_identifier | com.jenkin.Debug |
| username | 這里顯示的是開發者賬號 |
| keychain_name | login.keychain |
| readonly | false |
| team_id | 99WG99HF75 |
| verbose | false |
| force | false |
| skip_confirmation | false |
| shallow_clone | false |
| clone_branch_directly | false |
| force_for_new_devices | false |
| skip_docs | false |
| platform | ios |
+-----------------------+------------------------+
[17:55:38]: To not be asked about this value, you can specify it using 'git_url'
[17:55:38]: URL to the git repo containing all the certificates: git@172.16.11.154:repositories/test.git
[17:57:00]: Cloning remote git repo...
[17:57:00]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
[17:57:00]: ?? Successfully decrypted certificates repo
[17:57:00]: Verifying that the certificate and profile are still valid on the Dev Portal...
[17:57:05]: Couldn't find a valid code signing identity in the git repo for development... creating one for you now
+-------------------+------------------------------------------------+
| Summary for cert 2.68.2 |
+-------------------+------------------------------------------------+
| development | true |
| force | true |
| username | 這里顯示的是開發者賬號 |
| team_id | 99WG99HF75 |
| keychain_path | /Users/xyj/Library/Keychains/login.keychain-db |
| keychain_password | ******** |
| platform | ios |
+-------------------+------------------------------------------------+
[17:57:05]: Starting login with user '這里顯示的是開發者賬號'
[17:57:08]: Successfully logged in
[17:57:15]: Successfully generated FQV3SGXTZ9 which was imported to the local machine.
[17:57:17]: Verifying the certificate is properly installed locally...
[17:57:17]: Successfully installed certificate FQV3SGXTZ9
+-------------------------------------+------------------------------------+
| Summary for sigh 2.68.2 |
+-------------------------------------+------------------------------------+
| app_identifier | com.jenkin.Debug |
| username | 這里顯示的是開發者賬號 |
| force | true |
| cert_id | FQV3SGXTZ9 |
| provisioning_name | match Development com.jenkin.Debug |
| ignore_profiles_with_different_name | true |
| team_id | 99WG99HF75 |
| platform | ios |
| development | true |
| adhoc | false |
| skip_install | false |
| skip_fetch_profiles | false |
| skip_certificate_verification | false |
| readonly | false |
+-------------------------------------+------------------------------------+
[17:57:19]: Starting login with user '這里顯示的是開發者賬號'
[17:57:21]: Successfully logged in
[17:57:21]: Fetching profiles...
[17:57:22]: Verifying certificates...
[17:57:25]: No existing profiles found, that match the certificates you have installed locally! Creating a new provisioning profile for you
[17:57:32]: The name 'match Development com.jenkin.Debug' is already taken, using another one.
[17:57:32]: Creating new provisioning profile for 'com.jenkin.Debug' with name 'match Development com.jenkin.Debug 1512640652' for 'ios' platform
[17:57:37]: Downloading provisioning profile...
[17:57:38]: Successfully downloaded provisioning profile...
[17:57:38]: Installing provisioning profile...
/var/folders/w9/q16q5ckx2k3b3vmskgh3ksx00000gn/T/d20171207-41012-161tif9/profiles/development/Development_com.jenkin.Debug.mobileprovision
[17:57:38]: Installing provisioning profile...
[17:57:40]: ?? Successfully encrypted certificates repo
[17:57:40]: Pushing changes to remote git repo...
+---------------------+------------------------------------------------+---------------------------------------------------------+
| Installed Provisioning Profile |
+---------------------+------------------------------------------------+---------------------------------------------------------+
| Parameter | Environment Variable | Value |
+---------------------+------------------------------------------------+---------------------------------------------------------+
| App Identifier | | com.jenkin.Debug |
| Type | | development |
| Platform | | ios |
| Profile UUID | sigh_com.jenkin.Debug_development | 8d811267-9a90-4186-84ff-849270910564 |
| Profile Name | sigh_com.jenkin.Debug_development_profile-name | match Development com.jenkin.Debug 1512640652 |
| Profile Path | sigh_com.jenkin.Debug_development_profile-path | /Users/xyj/Library/MobileDevice/Provisioning |
| | | Profiles/8d811267-9a90-4186-84ff-849270910564.mobilepr |
| | | ovision |
| Development Team ID | sigh_com.jenkin.Debug_development_team-id | 99WG99HF75 |
+---------------------+------------------------------------------------+---------------------------------------------------------+
[17:57:40]: All required keys, certificates and provisioning profiles are installed ??
[17:57:40]: Setting Provisioning Profile type to 'development'
+------+-------------------------------------+-------------+
| fastlane summary |
+------+-------------------------------------+-------------+
| Step | Action | Time (in s) |
+------+-------------------------------------+-------------+
| 1 | Verifying required fastlane version | 0 |
| 2 | default_platform | 0 |
| 3 | match | 122 |
+------+-------------------------------------+-------------+
[17:57:40]: fastlane.tools finished successfully ??
這里主要說一下幾點:
1、git_url
:git_url
是git服務器地址,我沒指定git_url
, ,匹配證書的時候,要求我輸入服務器地址。輸入完成后就會clone git服務器的代碼,
2、驗證證書:keychain_password就是為這步而存在的,這里由于我沒在git服務器下載證書,所以沒找到,但是fastlane為我重新創建了一個
3、描述文件:其實我已經在證書(之前就創建的證書)上生成了描述文件,但是fastlane重新生成了證書,所以他沒找到描述文件,又自動給我重新生成了一個。
上面三種情況是fastlane的正常流程,但是我之前都創建好了,也就是說他現在的操作不是我想看到的。接下來我們將匹配開發證書的lane改成下面這樣
desc "匹配開發證書"
lane :matchDev do
match(type: "development", keychain_password: "git", git_url: "git@172.16.11.154:repositories/test.git")
end
并且登錄開發者賬號將新生成的證書和描述文件都刪掉,登錄git服務器,將證書下載并安裝好
再次在終端運行,結果如下:
fastlane matchDev
[11:12:18]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[11:12:21]: -------------------------------------------------
[11:12:21]: --- Step: Verifying required fastlane version ---
[11:12:21]: -------------------------------------------------
[11:12:21]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2 ?
[11:12:21]: ------------------------------
[11:12:21]: --- Step: default_platform ---
[11:12:21]: ------------------------------
[11:12:21]: Driving the lane 'ios matchDev' ??
[11:12:21]: -------------------
[11:12:21]: --- Step: match ---
[11:12:21]: -------------------
+-----------------------+-----------------------------------------+
| Summary for match 2.68.2 |
+-----------------------+-----------------------------------------+
| type | development |
| git_url | git@172.16.11.154:repositories/test.git |
| force | true |
| git_branch | master |
| app_identifier | com.jenkin.Debug |
| username | 這里顯示的是開發者賬號 |
| keychain_name | login.keychain |
| readonly | false |
| team_id | 99WG99HF75 |
| verbose | false |
| skip_confirmation | false |
| shallow_clone | false |
| clone_branch_directly | false |
| force_for_new_devices | false |
| skip_docs | false |
| platform | ios |
+-----------------------+-----------------------------------------+
[11:12:21]: Cloning remote git repo...
[11:12:21]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
[11:12:22]: ?? Successfully decrypted certificates repo
[11:12:22]: Verifying that the certificate and profile are still valid on the Dev Portal...
[11:12:26]: Installing certificate...
+-------------------+----------------------------------------------------------+
| Installed Certificate |
+-------------------+----------------------------------------------------------+
| User ID | BED2DYAVHS |
| Common Name | 這里顯示證書名字
|
| Organisation Unit | 99WG99HF75 |
| Organisation | ******** |
| Country | US |
| Start Datetime | Dec 8 02:58:55 2017 GMT |
| End Datetime | Dec 8 02:58:55 2018 GMT |
+-------------------+----------------------------------------------------------+
+-------------------------------------+------------------------------------+
| Summary for sigh 2.68.2 |
+-------------------------------------+------------------------------------+
| app_identifier | com.jenkin.Debug |
| username | 這里顯示的是開發者賬號 |
| force | true |
| cert_id | SP54MR68FC |
| provisioning_name | match Development com.jenkin.Debug |
| ignore_profiles_with_different_name | true |
| team_id | 99WG99HF75 |
| platform | ios |
| development | true |
| adhoc | false |
| skip_install | false |
| skip_fetch_profiles | false |
| skip_certificate_verification | false |
| readonly | false |
+-------------------------------------+------------------------------------+
[11:12:27]: Starting login with user '這里顯示的是開發者賬號'
[11:12:30]: Successfully logged in
[11:12:30]: Fetching profiles...
[11:12:31]: Verifying certificates...
[11:12:32]: Found 1 matching profile(s)
[11:12:32]: Recreating the profile
[11:12:34]: Creating new provisioning profile for 'com.jenkin.Debug' with name 'match Development com.jenkin.Debug' for 'ios' platform
[11:12:35]: Downloading provisioning profile...
[11:12:35]: Successfully downloaded provisioning profile...
[11:12:36]: Installing provisioning profile...
/var/folders/w9/q16q5ckx2k3b3vmskgh3ksx00000gn/T/d20171208-50529-1yh4aue/profiles/development/Development_com.jenkin.Debug.mobileprovision
[11:12:36]: Installing provisioning profile...
[11:12:37]: ?? Successfully encrypted certificates repo
[11:12:37]: Pushing changes to remote git repo...
+---------------------+------------------------------------+------------------------------------+
| Installed Provisioning Profile |
+---------------------+------------------------------------+------------------------------------+
| Parameter | Environment Variable | Value |
+---------------------+------------------------------------+------------------------------------+
| App Identifier | | com.jenkin.Debug |
| Type | | development |
| Platform | | ios |
| Profile UUID | sigh_com.jenkin.Debug_development | 63075bad-3ee8-449e-9ebb-251c50ea7 |
| | | f0c |
| Profile Name | sigh_com.jenkin.Debug_development | match Development |
| | _profile-name | com.jenkin.Debug |
| Profile Path | sigh_com.jenkin.Debug_development | /Users/xyj/Library/MobileDevice/P |
| | _profile-path | rovisioning |
| | | Profiles/63075bad-3ee8-449e-9ebb- |
| | | 251c50ea7f0c.mobileprovision |
| Development Team ID | sigh_com.jenkin.Debug_development | 99WG99HF75 |
| | _team-id | |
+---------------------+------------------------------------+------------------------------------+
[11:12:37]: All required keys, certificates and provisioning profiles are installed ??
[11:12:37]: Setting Provisioning Profile type to 'development'
+------+------------------------------+-------------+
| fastlane summary |
+------+------------------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------------------+-------------+
| 1 | Verifying required fastlane | 0 |
| | version | |
| 2 | default_platform | 0 |
| 3 | match | 16 |
+------+------------------------------+-------------+
[11:12:37]: fastlane.tools finished successfully ??
完成上面的步驟后,clone下你的代碼。工程下面多了兩個文件夾certs
、profiles
- certs文件夾下面包含一個.cer文件和一個.p12文件。命名都是以證書id,這兩個文件分別用于自己開發和授權團隊的小伙伴開發的。
- profiles文件夾下面存放的是描述文件
當你的倉庫里面沒這兩個,fastlane會為你重新創建證書和描述文件。如果有了。那就是上面這種情況,fastlane會直接幫你匹配好證書和描述文件。
至此,創建一個匹配開發證書的lane就算完成了。
2.創建一個打測試包的lane
創建一個lane,格式如下:
desc "打測試包"
desc "This will also make sure the profile is up to date"
lane :expIpa do
gym(clean: true, export_method: "development", configuration: "Debug")
end
這里主要涉及的工具為gym
,命令包含clean
,export_method
,configuration
三個參數,分別的含義為編譯之前是否clean、導出archive包的方式、編譯哪個configuration。
想了解更多參數,可在終端輸入fastlane action gym
或fastlane gym --help
查看文檔。
執行上面的命令后,在工程目錄下可以看到導出的ipa包。沒指定名字的話,ipa包的名字就是你的工程名。
3.創建一個上傳到測試包到第三方分發平臺的lane,這里以蒲公英為例
上傳測試包到蒲公英、firim等第三方平臺,都要到相應的第三方平臺注冊賬號,這些平臺一般都會制作fastlane的插件來支持fastlane上傳測試包,這里做簡單的介紹,查看詳細文檔請查看蒲公英官方文檔。
1、查看、安裝fastlane插件
在終端輸入 fastlane search_plugins
可以查看當前版本所有可用的插件,可以在里面看到pgyer
插件,想知道如何使用請異步蒲公英官網查看。
安裝pgyer插件:
fastlane add_plugin pgyer
安裝完成后你就可以使用fastlane action pgyer
來查看相關的參數以及使用了。
官網給出的例子是:
lane :beta do
gym(export_method: "ad-hoc")
pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")
end
以上的 api_key 和 user_key,請開發者在自己賬號(蒲公英)下的 應用管理 - App概述 - API 中可以找到,并替換到以上相應的位置。
上面,我們已經打好測試包了,下面我們就上傳測試到蒲公英。
lane如下:
desc "上傳到蒲公英"
lane :uploadPGY do
pgyer(api_key: "75284caf4b30813b45b557ca7d121b2d", user_key: "fa8d179bb6b6cf382931ee2e487e2321",ipa: "JenkinsDemo.ipa")
end
執行結果如下:
? test git:(master) ? fastlane uploadPGY
+-----------------------+---------+--------+
| Used plugins |
+-----------------------+---------+--------+
| Plugin | Version | Action |
+-----------------------+---------+--------+
| fastlane-plugin-pgyer | 0.2.1 | pgyer |
+-----------------------+---------+--------+
[10:48:01]: -------------------------------------------------
[10:48:01]: --- Step: Verifying required fastlane version ---
[10:48:01]: -------------------------------------------------
[10:48:01]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2 ?
[10:48:01]: ------------------------------
[10:48:01]: --- Step: default_platform ---
[10:48:01]: ------------------------------
[10:48:01]: Driving the lane 'ios uploadPGY' ??
[10:48:01]: -------------------
[10:48:01]: --- Step: pgyer ---
[10:48:01]: -------------------
[10:48:01]: The pgyer plugin is working.
[10:48:01]: build_file: JenkinsDemo.ipa
[10:48:01]: Start upload JenkinsDemo.ipa to pgyer...
[10:48:45]: Upload success. Visit this URL to see: https://www.pgyer.com/LnYN
+------+-------------------------------------+-------------+
| fastlane summary |
+------+-------------------------------------+-------------+
| Step | Action | Time (in s) |
+------+-------------------------------------+-------------+
| 1 | Verifying required fastlane version | 0 |
| 2 | default_platform | 0 |
| 3 | pgyer | 43 |
+------+-------------------------------------+-------------+
[10:48:45]: fastlane.tools finished successfully ??
可以看到,上傳成功后會給出一個鏈接,測試只需要打開這個鏈接就能掃碼安裝測試包了
小結:
上面幾個步驟,其實是可以在一個lane里面完成的。我改進后的lane如下
desc "打測試包并上傳蒲公英"
lane :dev do
# 調用匹配開發證書的lane
matchDev
expIpa
uploadPGY
end
當然,你可以這樣:
desc "打測試包并上傳蒲公英"
lane :dev do
match(type: "development", git_url: "git@172.16.11.154:repositories/test.git")
gym(clean: true, export_method: "development", configuration: "Debug")
pgyer(api_key: "75284caf4b30813b45b557ca7d121b2d", user_key: "fa8d179bb6b6cf382931ee2e487e2321",ipa: "JenkinsDemo.ipa")
end
這兩種方法,本質上是一樣的。上面只不過是lane之間的相互調用。
二、上傳一個TestFlight的測試包,
命令如下
desc "打beta包上傳TestFlight"
lane :beta do
match(type: "appstore", git_url: "git@172.16.11.154:repositories/test.git")
build_app(clean: true, output_name: "appstore", configuration: "Release", include_bitcode: true)
testflight(skip_submission: true)# 上傳testflight
end
上傳之前請做好前期的準備工作,在開發者賬號上創建APP,xcode上添加好appicon等。
首先:前期的匹配證書、導出ipa文件和打測試包差不多,改一下相應的參數就行了。只是增加了上傳到TestFlight,并且只是上傳一個ipa包并沒有將app相關的信息也上傳到TestFlight。
我在測試過程中遇到的問題:
1、因為是測試,所以一開始沒有添加相應尺寸的appicon,導致失敗。
2、在成功導出ipa包,準備上傳的時候報錯,如下圖 :
原因:上次上傳的動作被被記錄在UploadToken
文件夾下面了,我們要進入user/.itmstransporter/UploadTokens
該目錄下將里面的文件刪除,再次運行fastlane beta
命令,就能上傳成功了,上傳過程會比較久,但終端會顯示上傳的進度,大概如下
DEBUG [2017-12-09 17:39:46.83]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 1880200/93265945, 2% completed
DEBUG [2017-12-09 17:40:07.92]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 3744600/93265945, 4% completed
DEBUG [2017-12-09 17:40:16.55]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 4676800/93265945, 5% completed
DEBUG [2017-12-09 17:40:24.74]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 5609000/93265945, 6% completed
DEBUG [2017-12-09 17:40:36.80]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 6541200/93265945, 7% completed
DEBUG [2017-12-09 17:40:55.42]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 8405600/93265945, 9% completed
DEBUG [2017-12-09 17:41:09.38]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 9337800/93265945, 10% completed
DEBUG [2017-12-09 17:41:20.30]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 10270000/93265945, 11% completed
DEBUG [2017-12-09 17:41:39.45]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 12134400/93265945, 13% completed
DEBUG [2017-12-09 17:41:49.63]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 13066600/93265945, 14% completed
DEBUG [2017-12-09 17:41:58.10]: [Transporter]: INFO: File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 13998800/93265945, 15% completed
如果要直接上傳appstore,將上面的testfligh
t命令換成pload_to_app_store
命令就可以了。(因為這是制作demo,所以沒具體操作)。請自行嘗試!
結語
這篇博客只是提及了比較常用,也是比較實用的功能。起到拋磚引玉的作用fastlane
還有很多強大的功能,這里沒有一一提及,有興趣的小伙伴可以多多研究
相關的知識:
atool
xcodebuild 自動化構建
蘋果下使用Gitosis的搭建git的服務器
fastlane文檔