安装
fastlane的快速上手文档:https://docs.fastlane.tools/
这篇文章也不错
使用brew安装总是失败,更新了ruby后貌似就不失败了
N-000:~ admin$ brew install ruby
安装过程中,可能会遇到环境变量问题,按照提示在 .bash_profile文件中添加 export PATH="$HOME/.fastlane/bin:$PATH" 即可,如果文件不存在,可手动创建
使用蒲公英分发测试的话,需要安装蒲公英的传包插件, 使用 Fastlane 上传 App 到蒲公英
N-000:~ admin$ fastlane add_plugin pgyer
在安装插件时,可能会遇到错误
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.
// 运行gem install json -v '2.1.0' 可能会提示没权限
// 使用 sudo 即可解决
N-000:~ admin$ sudo gem install json -v '2.1.0'
使用
cd 到项目文件夹中
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请求需要
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/..."
enddesc "Runs all the tests"
lane :test do
scan
enddesc "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`)
enddesc "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 wantlane :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]# 修改配置文件 - 正式环境/测试环境
# 获取当前目录(/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表示以utf-8编码读取文件,要与当前代码文件的编码相同
content = lines.readif 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"
endlines.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时
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 ? "正式环境" : "测试环境"
updateStr = "fastlane: " + updateStrpgyer(
api_key: "xxx",
user_key: "xxx",
update_description: updateStr,
password: password,
install_type: password.length > 0 ? "2" : "1"
)# 通知钉钉机器人 - 项目组
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: "点击安装",
singleURL: installurl
}
}
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = truereq = Net::HTTP::Post.new(uri.request_uri)
req.add_field('Content-Type', 'application/json')
req.body = toSend.to_jsonres = https.request(req)
puts "------------------------------"
puts "Response #{res.code} #{res.message}: #{res.body}"endafter_all do |lane|
# This block is called, only if the executed lane was successful# slack(
#message: "Successfully deployed new App Update."
# )
enderror 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
【Fastlane|Fastlane 使用记录】待续。。。。