iOS 自动化部署和发布工具
准备工作
Xcode命令行工具
xcode-select --install
安装fastlane
gem install fastlane -NV
tips :如果安装慢,要更换源(https://www.jianshu.com/p/c7328c587201)。
或者
sudo gem install fastlane -n /usr/local/bin
或者
brew cask install fastlane
检查是否安装成功
fastlane --version
使用
设置
在命令行中cd到工程目录中
运行fastlane init 命令
环境变量设置 (export LC_ALL=en_US.UTF-8,export LANG=en_US.UTF-8),依据不同系统,配置 shell profile ( /.bashrc、/.bash_profile、~/.zshrc )
使用Gemfile
1. 在工程目录下创建./Gemfile :(source "https://rubygems.org"
gem "fastlane"),
2. 运行 [sudo] bundle update ,并将./Gemfile和./Gemfile.lock 添加至版本控制中。
3. 每次运行fastlane 时,使用bundle exec fastlane [lane]
4. 在CI服务器上,添加[sudo] bundle install 作为每一个build设置
5. 更新fastlane时,只需要运行[sudo] bundle update fastlane
运行测试
步骤
1. 在fastfile 添加lane
2. 使用 run_tests_action
* lane:test do run_tests(scheme:"MyAppTests") end
* 可指定run_tests 参数
4. 运行fastlane[tests lane]
在CI 上设置fastlane
发布build 结果 有相应的action
Beta版本发布
构建
* build_app action (lane:beta do build_app(scheme:"MyApp"))
脚本
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
# platform :ios do
# desc "Generate new localized screenshots"
# lane :screenshots do
# capture_screenshots(workspace: "SharedCarSuits.xcworkspace", scheme: "SharedCarSuits")
# end
# end
## cocopod
before_all do |lane, options|
# ...
end
#发布
# lane :production do
# # ...
# build(release: true)
# appstore # Deploy to the AppStore
# # ...
# end
#编译
lane :test do
run_tests(workspace: "testFastlane.xcworkspace")
end
# 每次添加 lane 需要指定证书
desc "发布 版本App Store"
lane :beta do
build_app(export_method: "app-store")
# pgyer(api_key: "b78238bb6a2a85e1045d56266c80d202", user_key: "ee8e5edc734c9f3ac2767eb021d26bd1", password: "123456", install_type: "2")
#sigh(adhoc:true) #如果要使用ad-hoc打包, 则需打开此项配置
#iOS 编译打包生成ipa文件
sigh(
# output_path: "build/adhoc",
team_id: "86MB5ZGM5F",
username: "2747763360@qq.com",
filename: "sharedCarSuits_Dis_Pro.mobileprovision",
app_identifier: "com.sharedCarSuits",
provisioning_name: "sharedCarSuits_Dis_Pro",
ignore_profiles_with_different_name: "true"
)
gym(
scheme:"testFastlane", # 项目名称,
clean:true, # 是否清空以前的编译信息true : 是
workspace:"testFastlane.xcworkspace",
export_method:"app-store", # app-store, ad-hoc, package, enterprise, development, developer-id
configuration:"Release",
output_directory:"./fastlane/build",
export_xcargs: "-allowProvisioningUpdates",
output_name:"testFastlane.ipa",#IPA 文件名
export_options: {
provisioningProfiles: {
"com.sharedCarSuits" => "sharedCarSuits_Dis_Pro",
}
}
)
#使用自动证书管理
# enable_automatic_code_signing(path: "SharedCarSuits.xcodeproj")
end
desc "打包到蒲公英"
lane :adhoc do
sigh(
adhoc: "true",
output_path: "build/adhoc",
team_id: "86MB5ZGM5F",
username: "2747763360@qq.com",
filename: "sharedCarSuits_AdHot_Pro.mobileprovision",
app_identifier: "com.sharedCarSuits",
provisioning_name: "sharedCarSuits_AdHot_Pro",
ignore_profiles_with_different_name: "true"
)
gym(
scheme:"testFastlane", # 项目名称,
clean:true, # 是否清空以前的编译信息true : 是
workspace:"testFastlane.xcworkspace",
export_method:"ad-hoc", # app-store, ad-hoc, package, enterprise, development, developer-id
configuration:"AdHoc",
output_directory:"./fastlane/build",
export_xcargs: "-allowProvisioningUpdates",
output_name:"testFastlane.ipa",#IPA 文件名
export_options: {
provisioningProfiles: {
"com.sharedCarSuits" => "sharedCarSuits_AdHot_Pro",
}
}
)
pgyer(api_key: "b78238bb6a2a85e1045d56266c80d202", user_key: "ee8e5edc734c9f3ac2767eb021d26bd1")
end
文档
加快打包
fastlane的官方repo地址:
https://github.com/fastlane/fastlane
fastlane的快速上手文档:
https://docs.fastlane.tools/
fastlane支持的action文档
https://docs.fastlane.tools/actions/
http://www.cocoachina.com/cms/wap.php?action=article&id=23396
https://docs.fastlane.tools/getting-started/ios/setup/
https://www.jianshu.com/p/c7328c587201