有的公司分工比较细,诸如项目打包、发布这些工作,都会有专门的测试人员去负责,这就为开发人员省去了大部分时间。当然,当你看到这篇文章时,就证明你所在的公司并不是这样。
不过不要担心,既然你找到了我,我就将Fastlane的使用技巧传授给你。
Fastlane是麻省理工学院批准的开源项目,可以将Mac、iOS、android项目的自动打包、发布等一系列繁琐的任务自动化。
Fastlane安装
-
打开终端输入xcode-select --install,若提示如下图,则说明已经安装了Xcode命令行工具;否则会弹出对话框,选择安装即可。
- 输入ruby -v查看ruby版本,要求2.0及以上版本。可以通过gem管理ruby版本,这里需要注意的是,ruby的镜像文件路径已经改为https://gems.ruby-china.org/
-
输入sudo gem install fastlane -NV ,通过gem安转fastlane。最近因为Xcode 9的问题,升级了fastlane。
Fastlane配置
- 打开终端,切换目录到包含xxx.xcodeproj的项目目录下输入fastlane init,期间会让输入Apple ID(开发者账号)及app_identifier等信息,可以根据需要自行选择填写。最后会在当前目录下生成fastlane文件夹。
-
进入fastlane文件夹,打开Appfile文件,里面是刚刚填写的一些信息。可以在里面配置多个app_identifier、apple_id信息。
- 打开Fastfile文件,里面便是自动生成的fastlane使用方法,当然,需要根据需要进行修改。
在编写fastfile文件之前,需要说明一下,Fastlane着实太强大,因此本文只介绍其中的一种方法:本机已经安装Signing Certificate及其对应的Provisioning Profile,也就是说打开Xcode,将Automatically manage signing选项去掉,手动进行选择,且能编译运行。
Fastfile文件的编写
-
App Store版本
# 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") # 设置某些服务是否有效 # 还可以使用modify_services,具体参考官网相关文档 produce( enable_services:{ push_notification: "on", } ) # 更新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, # Xcode 9之后,需要去掉 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的日志输出目录 export_method: "app-store", # Xcode 9增加export_method标签 output_directory: "/Users/xxx/Desktop") # ipa输出目录 end
-
Development版本
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") # 设置某些服务是否有效 # 还可以使用modify_services,具体参考官网相关文档 produce( enable_services:{ push_notification: "off", } ) # 将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)", export_method: "development", # Xcode 9增加export_method标签 output_directory: "/Users/xxx/Desktop" ) end
-
其他版本类似,此处不在给出。其中export_method标签对应的值有:
- export_method: "development"
- export_method: "enterprise"
- export_method: "app-store"
-
批量处理
desc "build all version ipa"
lane :all do |op|
t = op[:version]
ceshi version:t
release version:t
end
Fastlane使用
最后,只需在终端(相关项目目录下)轻轻敲入:
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
我们便可以去喝咖啡了,执行打包过程就交给fastlane去完成,是不是很爽?
Fastlane还有很多的功能供大家使用,比如match(能够使团队通过git同步证书和配置文件)、sigh(生成配置文件)、snapshot(生成截图)以及git的一些相关操作等等。大家可以到GitHub或者官网进行相关知识的学习。
授人以鱼不如授人以渔,传送门献上:
GitHub_Fastlane工具文档
Fastlane官网
关注微信公众号CodingArtist,可以第一时间得到文章更新通知! _
网友评论
ruby: 2.1
fastlane 2.8
初始化工程之后跑个build 命令
[10:02:35]: ------------------------------
[10:02:35]: --- Step: default_platform ---
[10:02:35]: ------------------------------
[10:02:35]: Driving the lane 'ios beta' 🚀
[10:02:35]: -----------------------
[10:02:35]: --- Step: build_app ---
[10:02:35]: -----------------------
[10:02:35]: You passed invalid parameters to 'build_app'.
[10:02:35]: Check out the error below and available options by running `fastlane action build_app`
+------------------+----------+
| Lane Context |
+------------------+----------+
| DEFAULT_PLATFORM | ios |
| PLATFORM_NAME | ios |
| LANE_NAME | ios beta |
+------------------+----------+
[10:02:35]: method `to_plist' not defined in Array
+------+------------------+-------------+
| fastlane summary |
+------+------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------+-------------+
| 1 | default_platform | 0 |
| 💥 | build_app | 0 |
+------+------------------+-------------+
[10:02:35]: fastlane finished with errors
Looking for related GitHub issues on fastlane/fastlane...
➡️ fastlane gym produces error: method `to_plist' not defined in Array
https://github.com/fastlane/fastlane/issues/11503 [open] 26 💬
3 days ago
rvm all do gem uninstall fastlane
gem uninstall fastlane
gem install fastlane
What would you like to use fastlane for?
然后就停止,直接崩溃crash了!!
[!] Insufficient permissions for your Apple ID:
User 1*****@163.com doesn't have enough permission for the following action: user_details_data
上面那个Apple ID是企业版的账号,然后我换一个99刀的个人账号,换另一个项目重新执行就可以了,疑问,是企业版不能用fastlane打包吗???
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")
这两步具体是干什么的,看不太明白,这里面的xxx需要怎么修改?
teamid: "5JC8GZ432G") 这里的teamid从哪得到?
代码签名证书 "iPhone Distribution: xxx Co.,Ltd. (5JC8GZ432G)" 这个又是怎么得到的?
谢谢~
[13:08:52]: ▸ Archive Succeeded
[13:08:52]: Generated plist file with the following values:
[13:08:52]: ▸ -----------------------------------------
[13:08:52]: ▸ {
[13:08:52]: ▸ "method": "ad-hoc"
[13:08:52]: ▸ }
[13:08:52]: ▸ -----------------------------------------
[13:08:52]: $ /usr/bin/xcrun /Users/caoyunxiao/.fastlane/bin/bundle/lib/ruby/gems/2.2.0/gems/fastlane-2.35.1/gym/lib/assets/wrap_xcodebuild/xcbuild-safe.sh -exportArchive -exportOptionsPlist '/var/folders/6j/2n47snc95l763df22wshs42m0000gn/T/gym_config20170606-94787-zuo3uc.plist' -archivePath /Users/caoyunxiao/Library/Developer/Xcode/Archives/2017-06-06/my-app\ 2017-06-06\ 13.06.52.xcarchive -exportPath '/var/folders/6j/2n47snc95l763df22wshs42m0000gn/T/gym_output20170606-94787-zet2cx'
RVM detected, forcing to use system ruby
Warning! PATH is not properly set up, '/Users/caoyunxiao/.rvm/gems/ruby-2.3.3/bin' is not at first place.
Usually this is caused by shell initialization files. Search for 'PATH=...' entries.
You can also re-add RVM to your profile by running: 'rvm get stable --auto-dotfiles'.
To fix it temporarily in this shell session run: 'rvm use ruby-2.3.3'.
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
Now using system ruby.
lane :all do |op|
t = op[:version]
ceshi version:t
release version:t
end
这里批量处理的意思,是把'fastlane ceshi' ,'fastlane release'两个命令连在一起执行的意思吗?