初窺 fastlane 一鍵打包上傳蒲公英平臺和App Store
阿新 • • 發佈:2019-01-06
很久之前就聽說自動化打包如何方便,只是自己一直沒有去嘗試過,最近因為專案需求,自己也嘗試了一把。關於fastlane網上資料非常多,功能如何強大,自動化測試、證書管理、截圖等。但是我這裡只使用自動化打包的功能,畢竟適合自己專案團隊的方式才是最好的方式。
安裝faltlane以及初始化專案fastlane
-
faltlane的安裝就不講了,請參考官方網站傳送門
-
進入專案工程,初始化fastlane
cd your project path
fastlane init
不知道為什麼,用公司電腦每次進到這裡就卡住了,翻了牆也不行,更改了源也不行,如果有小夥伴知道請給我留言,不過只要生成了fastlane/Fastfile 檔案就行了,後面依然可以操作。
gem sources
https://gems.ruby-china.org/
https://rubygems.org
- 新增蒲公英外掛,成功後,fastlane資料夾出現Pluginfile檔案
fastlane add_plugin pgyer
編寫Fastfile,打包ad-hoc版本上傳蒲公英
- 編寫Fastfile檔案,見程式碼
default_platform(:ios) platform :ios do desc "上傳到蒲公英" # 使用方法: # 1、進入對應專案,新增蒲公英外掛 fastlane add_plugin pgyer # 2、執行打包命令 fastlane adhoc name:your_project_name lane :adhoc do |options| name = options[:name] gym( clean:true, # 是否清空以前的編譯資訊 true:是 scheme: name, # 自己專案名稱 workspace: "#{name}.xcworkspace", # 自己專案名稱xcworkspace(使用cocoapods才會生成) export_method:"ad-hoc", #app-store,ad-hoc,enterprise,development configuration:"AdHoc", output_directory:"./fastlane/build", # 打包後的 ipa 檔案存放的目錄 export_xcargs: "-allowProvisioningUpdates", #訪問鑰匙串 output_name: "#{name}.ipa",# ipa 檔名 silent:true,#隱藏沒有必要的資訊 export_options: { provisioningProfiles: { "com.you.bundleIdentifier" => "your_AdHoc" # bundleid,打包用的證書名字 } } ) pgyer( api_key: "your_apikey", # 從蒲公英專案詳情中獲取的 apikey user_key: "userKey", # 從蒲公英專案詳情中獲取的 userkey password: "123456", # 密碼 update_description: "本次測試更新的文字說明"#"description" # 本次測試更新的文字說明(引數設定) ) end end
- 使用方法
在終端進入專案路徑執行命令:fastlane adhoc name:your_project_name
-
打包之前,在Xcode中配置好Version和Build版本(這裡沒有使用外掛,手動管理),證書要配置正確,之前這裡配成了App Store的證書,打包會出現異常
-
打包上傳成功的提示,然後會收到蒲公英的郵件或者簡訊提醒
falstlane 打包上傳App Store
之前在網上查看了一番別人的部落格,總的來說就是不能直接拿來用。沒辦法,自己看了一遍官方文件,研究了一番,探索出了自己的一個版本.現將探索歷程記錄在下.
官方文件說要上傳App Store需要使用deliver 官方傳送門
- 第一步進入自己的專案工程初始化deliver
cd [your_project_folder]
fastlane deliver init
這個時候fastlane會讓你輸入開發者賬號和APP的Bundle Identifier,如果Bundle Identifier和iTunes Store中任意一個不存在,deliver會初始化失敗.
請在初始化之前建立對應的APP ID 和iTunes Store中建立對應APP.
初始化完成之後會,fastlane會下載iTunes Store中APP的配置資訊(如果之前配置了)
效果如下:
- 根據官方文件的描述,編寫Deliverfile檔案
利用Deliverfile檔案配置iTunes Store需要填寫配置相關的資訊(不明白的資訊和iTunes Store中對照下就知道了)
# The Deliverfile allows you to store various iTunes Connect metadata
# For more information, check out the docs
# https://docs.fastlane.tools/actions/deliver/
# 根據iTunes Store 資訊設定
username "[email protected]" # Apple ID email address
app_identifier("com.my.MyFastLaneDemo") # bundle identifier
#ipa("./fastlane/release_ipa/My.ipa") # 如果沒有這個選項,只有metadata會被上傳 ipa路徑
copyright("版權資訊 2018") #版權資訊
#submit_for_review(false) #是否提交稽核,true表示立馬提交稽核
screenshots_path("./fastlane/screenshots") # 截圖圖片展示
price_tier 0 #app 出售價格
trade_representative_contact_information( #iTunes store 綜合資訊處資訊
first_name: "jie", #名
last_name: "wang", #姓
address_line1: "軟體園", #地址
address_line2: "",
address_line3: "",
city_name: "Chengdu", # 城市
state: "SICHUAN", # 省
country: "China", #國家
postal_code: "610000", # 郵編
phone_number: "+86 18283606699", # 手機
email_address: "[email protected]", #郵箱
)
app_review_information( # app稽核資訊
first_name: "jie", # 名
last_name: "wang", #姓
phone_number: "+86 18283606699", #聯絡資訊電話號碼
email_address: "[email protected]", #聯絡資訊郵箱
demo_user: "12345678", #稽核測試賬號
demo_password: "1234", # 稽核測試密碼
notes: "備註資訊" # iTunes Store 稽核資訊備註
)
#提交稽核資訊:加密, idfa 等
submission_information({ # 引數參考地址 https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/tunes/app_submission.rb
export_compliance_encryption_updated: false,
export_compliance_uses_encryption: false,
content_rights_contains_third_party_content: false,
add_id_info_uses_idfa: false
})
# 模板參考地址 https://github.com/fastlane/fastlane/blob/master/deliver/assets/example_rating_config.json
app_rating_config_path "./fastlane/metadata/itunes_rating_config.json" #年齡分級配置
name({
'zh-Hans' => "MyFastLaneDemoTest" # app名稱
})
description({ #iTunes Store 中描述資訊
'zh-Hans' => "APP的描述資訊,用於APP功能的描述和介紹不能少於10個字元"
})
release_notes({
'zh-Hans' => "第一個版本測試" #這個新版本資訊,iTunes Store 新增內容處該填的內容
})
keywords( # 收縮關鍵詞
"zh-Hans" => "FastLane, 美女"
)
promotional_text( # 本地化宣傳文字資訊介紹
"zh-Hans" => "本地化宣傳文字資訊介紹",
)
support_url({ # 技術支援網址(URL)
'zh-Hans' => "http://www.baidu.com"
})
marketing_url({ #營銷網址
'zh-Hans' => "http://www.baidu.com"
})
privacy_url({
'zh-Hans' => "http://www.baidu.com"
})
app_icon('./fastlane/metadata/AppIcon.png') #應用圖示1024 * 1024
primary_category("Utilities") #類別設定 參考網站https://docs.fastlane.tools/actions/upload_to_app_store/#reference
# primary_first_sub_category "Card"
# primary_second_sub_category "Casino"
# 要設定的次要類別 無
# secondary_category
# 設定的次要第一個子類別 無
# secondary_first_sub_category
# 設定的次要第二個子類別 無
# secondary_second_sub_category
automatic_release true #稽核過之後自動釋出
- 編輯Fastfile檔案,編寫打包release版本程式碼
default_platform(:ios)
platform :ios do
desc "打包release版本"
# 執行打包命令 fastlane buile_release name:your project name
lane :buile_release do |options|
name = options[:name]
gym(
clean:true, # 是否清空以前的編譯資訊 true:是
scheme: name, # 自己專案名稱
workspace: "#{name}.xcworkspace", # 自己專案名稱xcworkspace(使用cocoapods才會生成)
export_method:"app-store", #app-store,ad-hoc,enterprise,development
configuration:"Release",
output_directory:"./fastlane/release_ipa", # 打包後的 ipa 檔案存放的目錄
export_xcargs: "-allowProvisioningUpdates", #訪問鑰匙串
output_name: "#{name}.ipa",# ipa 檔名
silent:true, #隱藏沒有必要的資訊
include_bitcode: true,
export_options: {
provisioningProfiles: {
"com.you.bundleIdentifier" => "your_appStore" # bundleid,打包用的證書名字,這裡也可以採用引數傳遞,看個人喜好吧
}
}
)
end
desc "Upload to App Store"
lane :upload do |options|
deliver( #提交App Store稽核
ipa:"./fastlane/release_ipa/#{options[:name]}.ipa", #ipa路徑
force : false, #是否跳過網頁審查,上傳過程中會形成一個預覽介面
submit_for_review(true) #上傳成功後立馬提交稽核
)
end
# 使用方法 fastlane build_upload name:your project name
desc "build relese ipa and upload to App Store"
lane :build_upload do |options|
buile_release(options)
upload(options) #提交App Store稽核
end
end
- 使用方法:進入專案工程
fastlane build_upload name:your project name
- 演示效果
問題
由於mac系統更新或者其他原因導致fastlane的問題。
Ignoring gem-wrappers-1.3.2 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.3.2
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem fastlane (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/fastlane:22:in `<main>'
解決辦法:
1、指定預設的ruby版本
rvm use 2.3.7 --default
2、重新安裝
brew cask reinstall fastlane
3、然後看控制檯資訊
Updating installed gems
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
Cleaning up installed gems...
Clean Up Complete
Detected shell config file at path '~/.bash_profile'
Please add the following line to your bash profile:
export PATH="$HOME/.fastlane/bin:$PATH"
After doing so close the terminal session and restart it to start using fastlane