安裝
fastlane的快速上手文檔:https://docs.fastlane.tools/
這篇文章也不錯(cuò)
使用brew安裝總是失敗决侈,更新了ruby后貌似就不失敗了
N-000:~ admin$ brew install ruby
安裝過程中其垄,可能會(huì)遇到環(huán)境變量問題,按照提示在 .bash_profile文件中添加 export PATH="$HOME/.fastlane/bin:$PATH" 即可卫病,如果文件不存在警医,可手動(dòng)創(chuàng)建
使用蒲公英分發(fā)測試的話亿胸,需要安裝蒲公英的傳包插件, 使用 Fastlane 上傳 App 到蒲公英
N-000:~ admin$ fastlane add_plugin pgyer
在安裝插件時(shí),可能會(huì)遇到錯(cuò)誤
An error occurred while installing json (2.1.0), and Bundler cannot continue.
Make sure that `gem install json -v '2.1.0'` succeeds before bundling.
// 運(yùn)行g(shù)em install json -v '2.1.0' 可能會(huì)提示沒權(quán)限
// 使用 sudo 即可解決
N-000:~ admin$ sudo gem install json -v '2.1.0'
使用
cd 到項(xiàng)目文件夾中
N-000:fastlane_test admin$ fastlane init
初始化中需要輸入Apple ID....
這里列出來init成功后的预皇,自己修改后的fastfile文件侈玄,
# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# 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:
# update_fastlane
# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.28.3"
default_platform :ios
# post請(qǐng)求需要
require 'net/http'
require 'uri'
require 'json'
#https://docs.fastlane.tools/actions/
platform :ios do
before_all do
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
end
desc "Runs all the tests"
lane :test do
scan
end
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
gym # Build your app - more options available
pilot
# sh "your_script.sh"
# You can also use other beta testing services here (run `fastlane actions`)
end
desc "Deploy a new version to the App Store"
lane :release do
# match(type: "appstore")
# snapshot
gym # Build your app - more options available
deliver(force: true)
# frameit
end
# You can define as many lanes as you want
lane :dftt_adhoc_1 do
dftt_ad_hoc(release: true)
end
lane :dftt_adhoc_0 do
dftt_ad_hoc(release: false)
end
# arctive with ad_hoc and autoUplod to pgyer
desc "dftt_ad_hoc(release:true/false)"
lane :dftt_ad_hoc do |options|
isrelease = options[:release]
# 修改配置文件 - 正式環(huán)境/測試環(huán)境
# 獲取當(dāng)前目錄(/fastlane)的父目錄
patch = File.expand_path("..", File.dirname(__FILE__)).to_s
patch = patch + "/Class/InterFace/product.h"
File.open(patch,"r+:utf-8") do |lines| #r:utf-8表示以u(píng)tf-8編碼讀取文件,要與當(dāng)前代碼文件的編碼相同
content = lines.read
if isrelease
content = "#ifndef product_h\n#define product_h\n#define Release 1\n#endif"
else
content = "#ifndef product_h\n#define product_h\n#define Release 0\n#endif"
end
lines.seek(0)
lines.write(content)
end
# 打包ip
ipadir = “fs_build/“ + Time.new.strftime('%Y-%m-%d_%H:%M')
ipaname = "newapp"
gym(
workspace: "xxxxxx.xcodeproj/project.xcworkspace", # 必須是.xcworkspace路徑吟温,
export_method: "ad-hoc", # app-store, ad-hoc, enterprise, development,
# configuration: "Debug", # Defaults to 'Release'
scheme: "xxxxxx", # scheme Name
silent: true, # 隱藏不必要的信息 在bulding時(shí)
clean: true, # bulding前clean工程
output_directory: ipadir, # 輸出文件夾. Defaults to current directory.
output_name: ipaname, # ipa fileName
include_bitcode: false # close bitcode
)
# 上傳到蒲公英
password = "xxx"
updateStr = isrelease ? "正式環(huán)境" : "測試環(huán)境"
updateStr = "fastlane: " + updateStr
pgyer(
api_key: "xxx",
user_key: "xxx",
update_description: updateStr,
password: password,
install_type: password.length > 0 ? "2" : "1"
)
# 通知釘釘機(jī)器人 - 項(xiàng)目組
patch = ipadir + "/#{ipaname}.ipa"
appversion = get_ipa_info_plist_value(ipa: patch, key: "CFBundleShortVersionString")
appname = get_ipa_info_plist_value(ipa: patch, key: "CFBundleDisplayName")
# 這里不支持獲取序仙,只能先寫死了
installurl = "https://www.pgyer.com/xxx"
# url = "https://oapi.dingtalk.com/robot/send?access_token=bba95cff81603acd229d6a231fd351d21061888c2efaxxxx"
# test route
url = "https://oapi.dingtalk.com/robot/send?access_token=4b4f9daa81de6dbb6df459041a931a6e86c9020a38fxxx"
toSend = {
msgtype: "actionCard",
actionCard: {
title: "",
text: "### #{appname}#{appversion}\n" + "- #{updateStr}\n" + "- password:#{password}",
singleTitle: "點(diǎn)擊安裝",
singleURL: installurl
}
}
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.add_field('Content-Type', 'application/json')
req.body = toSend.to_json
res = https.request(req)
puts "------------------------------"
puts "Response #{res.code} #{res.message}: #{res.body}"
end
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://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://docs.fastlane.tools/actions
# fastlane reports which actions are used
# No personal data is recorded. Learn more at https://github.com/fastlane/enhancer
待續(xù)。鲁豪。潘悼。。