fastlane(自动化打包)
安装:
sudo gem install -n /usr/local/bin fastlane
复制代码
1.在工程目录下,会在工程下生成fastlane文件夹
fastlane init
复制代码
然后会让你输入开发者账号和密码
自定义fastFile文件编写
- appStore版本
# You can define as many lanes as you want
desc "Deploy a new version to the App Store"
lane :release do |op|
increment_version_number(version_number: op[:version]) #根据入参version获取app版本号
increment_build_number(build_number: op[:version]) #将build号设置与app版本号相同
# 设置app的info.plist文件项
set_info_plist_value(path: "./xxx/Info.plist", #info.plist文件目录
key: "UIFileSharingEnabled", # key,将plist文件以Source Code形式打开可查询对应的key
value: false) # value
# 设置自定义plist文件项,用于给app配置不同的服务器URL
set_info_plist_value(path: "./xxx/hostAddress.plist",
key: "host",
value: "https:/zhengshiServer:xx/xxx/xxx")
# 更新Provisioning Profile
# 在项目当前目录下创建provisions文件夹,并将App Store版本的.mobileprovision文件保存在里面,名称随意。
update_project_provisioning(profile: "./provisions/appstore.mobileprovision")
# 更新项目团队
update_project_team(path: "xxx.xcodeproj",
teamid: "5JC8GZ432G")
# 开始打包
gym(use_legacy_build_api: true,
output_name: "appstore", # 输出的ipa名称
silent: true, # 隐藏没有必要的信息
clean: true, # 在构建前先clean
configuration: "Release", # 配置为Release版本
codesigning_identity: "iPhone Distribution: xxx Co.,Ltd. (5JC8GZ432G)", # 代码签名证书
buildlog_path: "./fastlanelog", # fastlane构建ipa的日志输出目录
output_directory: "/Users/xxx/Desktop") # ipa输出目录
end
复制代码
- 测试版本
desc "Build a new version use the ceshi"
lane :ceshi do |op|
increment_version_number(version_number: op[:version])
increment_build_number(build_number: op[:version])
set_info_plist_value(path: "./xxx/Info.plist",
key: "UIFileSharingEnabled",
value: true)
set_info_plist_value(path: "./xxx/hostAddress.plist",
key: "host",
value: "https:/ceshiServer:xx/xxx/xxx")
# 将Development版本的.mobileprovision文件保存在里面,名称随意。
update_project_provisioning(profile: "./provisions/development.mobileprovision")
update_project_team(path: "xxx.xcodeproj",
teamid: "5JC8GZ432G")
gym(use_legacy_build_api: true,
output_name: "ceshi",
silent: true,
clean: true,
configuration: "Debug",
buildlog_path: "./fastlanelog",
codesigning_identity: "iPhone Developer: xxx (xxxxxxxxxx)",
output_directory: "/Users/xxx/Desktop"
)
end
复制代码
- 批量处理
desc "build all version ipa"
lane :all do |op|
t = op[:version]
ceshi version:t
release version:t
end
复制代码
执行命令输出对应的ipa
fastlane ceshi version:1.0.0 // 打包ceshi环境ipa,app版本号为1.0.0
fastlane release version:1.0.0 // 打包App Store版本ipa,app版本号为1.0.0
fastlane all version:1.0.0 // 打包ceshi、App Store版本ipa,app版本号为1.0.0
复制代码
最终成功的方案eg:
fastlane自动化打包
ad-hoc版本:
desc "Build a new version use the ceshi"
lane :ceshi do |op|
increment_version_number(version_number: op[:version])
increment_build_number(build_number: op[:version])
set_info_plist_value(path: “./xxxx/Info.plist", # 工程中的plist文件
key: "UIFileSharingEnabled",
value: true)
set_info_plist_value(path: “./xxxxx/hostAddress.plist",
key: "host",
value: "https://www.xxxx.com/“)
# 将Development版本的.mobileprovision文件保存在里面,名称随意。
update_project_provisioning(profile: "./xxxxx/provisions/Distribution_adhoc.mobileprovision")
update_project_team(path: “xxxx.xcodeproj",
teamid: "9Z4ZJ5K398")
# 开始打包
gym(# use_legacy_build_api: true,
scheme: "xxxxxxx",
output_name: “xxxxxx”, # 输出的ipa名称
silent: true, # 隐藏没有必要的信息
clean: true, # 在构建前先clean
configuration: "Debug", # 配置为Release版本
codesigning_identity: “iPhone Distribution: xxxxxx Network Technology Co., Ltd. (9Z4Zj5K398)”, # 代码签名证书
export_method:’ad-hoc’, #指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development, 和developer-id,即xcodebuild的method参数
buildlog_path: "./fastlanelog", # fastlane构建ipa的日志输出目录
output_directory: "./fastlane") # ipa输出目录
end
复制代码
在使用fastlane遇到的问题
- 1.gem路径找不到问题 解决办法----卸载fastlane重装
- 2.关掉Bitcode
- 3.手动管理证书
- 4.关于Fastfile的问题
-
- 1.配置工程
Info.plist
路径
- 1.配置工程
-
- 2.新建
hostAddress.plist
,并配置好路径(功能是设置服务器地址)
- 2.新建
-
- 3.添加
mobileprovision
配置文件(配置的文件名和路经要正确)
- 3.添加
-
- 4.配置你工程
xxxx.xcodeproj
和teamid
(每个开发者账号都会对应一个teamid)
- 4.配置你工程
-
- 5.
gym
的配置gym(# use_legacy_build_api: true, 复制代码
- 5.
-