打包工具fastlane
什么是Fastlane?
Fastlane可以非常快速简单的搭建一个自动化发布服务,并且支持iOS,Android,MacOS。Fastlane执行的底层并不是自己实现的,而是调用其他的插件或者工具执行的。比如说打包:Fastlane中gym工具只是xcodebuild工具的一个封装,调用的还是xcodebuild的打包命令。Fastlane使用Ruby语言。Fastlane的插件工具叫做action,每一个action对应一个功能。 Fastlane的Git地址
Fastlane的安装
1、安装Xcode命令行工具,在终端输入
xcode-select --install
如果没有安装则会进行安装,如果已经安装,则提示
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
2、安装Fastlane,在终端输入
// 方式一:Using RubyGems 官方建议
sudo gem install fastlane -NV
// 方式二:Using Homebrew
brew case install fastlane
// 方式三:
sudo gem install fastlane --verbose
检查是否安装成功,在终端输入,可以看到Fastlane的版本信息
fastlane --version
Fastlane的初始化工程
sudo fastlane init
命令行会让做选择
[14:03:58]: What would you like to use fastlane for?
1. 📸 Automate screenshots
2. 👩✈️ Automate beta distribution to TestFlight
3. 🚀 Automate App Store distribution
4. 🛠 Manual setup - manually setup your project to automate your tasks
? 4
2:TestFlight;3:App Store;4:企业版
如果需要升级fastlane版本的话,用下面命令
gem install fastlane
工程中目录下新增文件,见下图:
fastlane的使用
Appfile里是账号信息,Fastfile里是需要编写的打包脚本,有效脚本如下,更加复杂的我这里就不多说了
default_platform(:ios)
platform :ios do
desc "打测试包"
lane :archive do #执行命令打包是fastlane xx 同此处一样
puts "开始打包"
gym(
scheme: "HelloWorld", #项目的scheme
workspace: "HelloWorld.xcworkspace", #项目使用CocoaPods需要加上
configuration: "DebugUAT",
output_directory: "~/Desktop/HelloWorld1/ipa",#打包的ipa存放路径
output_name: "HelloWorld.ipa", #打包的ipa名称
include_bitcode: false,
include_symbols: true,
export_options: {
method: "enterprise", #根据具体情况定
thinning: "<none>",
provisioningProfiles: {
"com.xx.n" => "wxxtest",
}
}
)
end
end
编写完脚本之后,运行命令fastlane archive
开始打包,打包过程就是使用xcodebuild: 生成Archive、导出ipa的过程。打包成功后还可以上传到特定的网站,在这里就先不说了。