1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > ios 自动打包命令_iOS开发之使用fastlane工具实现自动化打包发布(示例代码)

ios 自动打包命令_iOS开发之使用fastlane工具实现自动化打包发布(示例代码)

时间:2021-04-27 20:04:30

相关推荐

ios 自动打包命令_iOS开发之使用fastlane工具实现自动化打包发布(示例代码)

1、Fastlane工具的简介:

Fastlane是一套使用Ruby写的自动化工具集,旨在简化Android和iOS的部署过程,自动化你的工作流。它可以简化一些乏味、单调、重复的工作,像截图、代码签名以及发布App。可以使用 fastlane 上传到firim和蒲公英。

2、Fastlane工具的功能分类:

Beta内测相关

Misc其他的东西

3、Fastlane工具的安装:

《1》检查Ruby版本,需要2.0及以上版本,在终端输入以下命令:

ruby -v

《2》需要注意的是需要将gem的source改为https://gems.ruby-/,在终端输入以下命令:

gem source

检查结果为:

*** CURRENT SOURCES ***

/

http://gems.ruby-/

《3》检查Xcode命令行工具是否安装,在终端输入以下命令:

xcode-select --install

如果没有安装会进行安装,如果已经安装则会提示如下:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

解决办法:

sudo xcode-select --switch /Library/Developer/CommandLineTools/

《4》安装Fastlane,在终端输入命令如下:

sudo gem install fastlane --verbose

如果安装出现以下错误:

ERROR:While executing gem ... (Gem::FilePermissionError)

You don‘t have write permissions for the /usr/bin directory.

解决办法:

sudo gem install -n /usr/local/bin fastlane或sudo gem install fastlane -NV

《5》检查Fastlane是否安装正确,输入以下命令:

fastlane --version

4、Fastlane工具的使用:

《1》使用命令切换到项目工程:

cd /Users/yh/Desktop/xxx/FloatingWindow_Demo

《2》初始化Fastlane:

fastlane init

如果初始化出现以下错误:

[!] Unable to locate Xcode. Please make sure to have Xcode installed on your machine

解决办法:

在Xcode中没有设置“Command Line Tools”:打开Xcode偏好设置,选择"Location"选项卡,选择相应的“Command Line Tools”即可。比如:Xcode9.1

《3》提示输入开发者账号、密码, 登录成功后会提示你输入App名称,是否需要下载你的App的metadata。点y等待就可以了:

完成后显示结果为:

+----------------+--------------------------------+

| Summary for produce 2.98.0|

+----------------+--------------------------------+

| username

| team_id| xxxxxx |

| itc_team_id| xxxxxx|

| platform | ios|

| app_identifier | com.xxxxxx.FloatingWindow-Demo |

| skip_itc | true |

| sku| xxxxxx|

| language | English|

| skip_devcenter | false|

+----------------+--------------------------------+

注意事项:

A、会问你想使用fastlane做什么?这里我们输入3,自动发布到Apple Store。

B、接着会问是否想用fastlane来管理你的app metadata。输入y,fastlane则会下载现有的元数据和屏幕截图。输入n,不做任何操作,仍然能使用fastlane上传app到App Store。

C、如果最后出现fastlane release,就表示init成功了。

5、Fastlane工具组成的内容:

《1》初始化成功后会在当前工程目录生成一个fastlane文件夹和一个Gemfile文件, 文件夹目录为

《2》Appfile:存放App的apple_id,team_id, app_identifier等信息

《3》Deliverfile:存放发布的配置信息

《4》Fastfile:工作编辑文件

《5》metadata:App元数据

《6》screenshots:商店应用截图

6、操作并编辑Fastfile文件:

# 自动更新fastlane 工具

# update_fastlane

#需要的fastlane的最小版本,在每次执行之后会检查是否有新版本,如果有会在最后末尾追加新版本提醒

fastlane_version "2.98.0"

default_platform(:ios)

platform :ios do

#lane之前的操作

before_all do

# ENV["SLACK_URL"] = "/services/..."

cocoapods

end

#执行lane成功后的回调

after_all do |lane|

# slack(

# message: "Successfully deployed new App Update."

# )

end

desc "提交一个新的Beta版本到 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(scheme: "FloatingWindow_Demo") # Build your app - more options available

pilot

# sh "your_script.sh"

end

desc "部署一个新版本到App Store"

lane :release do

# match(type: "appstore")

# snapshot

gym(scheme: "FloatingWindow_Demo") # Build your app - more options available

deliver(force: true)

# frameit

end

# 你可以定义自己的lane

desc "打包到蒲公英"

lane :test do |options|

gym(

clean:true, #打包前clean项目

export_method: "ad-hoc", #导出方式

scheme:"shangshaban", #scheme

configuration: "Debug",#环境

output_directory:"./app",#ipa的存放目录

output_name:get_build_number()#输出ipa的文件名为当前的build号

)

#蒲公英的配置 替换为自己的api_key和user_key

pgyer(api_key: "xxxxxxx", user_key: "xxxxxx",update_description: options[:desc])

end

# 如果流程发生异常会走这里并终止

error do |lane, exception|

# slack(

# message: exception.message,

# success: false

# )

end

end

7、Fastlane插件命令:

《1》列出所有可用插件

fastlane search_plugins

《2》搜索指定名称的插件:

fastlane search_plugins [query]

《3》添加插件:

fastlane add_plugin [name]

《4》安装插件:

fastlane install_plugins

其它命令字:

gym:编译打包生成 ipa 文件

sigh:可以生成并下载开发者的 App Store 配置文件

deliver:用于上传应用的二进制代码,应用截屏和元数据到 App Store

snapshot:可以自动化iOS应用在每个设备上的本地化截屏过程

scan:自动化测试工具,很好的封装了 Unit Test

match :同步团队每个人的证书和 Provision file 的超赞工具

8、使用Fastlane上传到蒲公英:

《1》打开终端输入命令:

fastlane add_plugin pgyer

《2》新建一个定义自己的lane,option用于接收我们的外部参数,这里可以传入当前build的描述信息到蒲公英平台:

desc "打包到蒲公英"

lane :test do |options|

gym(

clean:true, #打包前clean项目

export_method: "ad-hoc", #导出方式

scheme:"FloatingWindow_Demo", #scheme

configuration: "Debug",#环境

output_directory:"./app",#ipa的存放目录

output_name:get_build_number()#输出ipa的文件名为当前的build号

)

sigh( #发布打包

clean:true, #打包前clean项目

export_method: "app-store”, #导出方式

scheme:"FloatingWindow_Demo", #scheme

configuration: “Release”,#环境

output_directory:"./app",#ipa的存放目录

output_name:get_build_number()#输出ipa的文件名为当前的build号

)

#蒲公英的配置 替换为自己的api_key和user_key

pgyer(api_key: "xxxxxxxxxxxx", user_key: "xxxxxxxxxxxx",update_description: options[:desc])

end

《3》在工作目录的终端执行命令:

fastlane test desc:测试蒲公英打包

9、使用Fastlane上传到firim:

《1》打开终端输入命令:

fastlane add_plugin firim

《2》新建一个定义自己的lane

desc "打包到fir”

lane :test2 do |options|

gym(#测试打包

clean:true, #打包前clean项目

export_method: "ad-hoc", #导出方式

scheme:"FloatingWindow_Demo", #scheme

configuration: "Debug",#环境

output_directory:"./app",#ipa的存放目录

output_name:get_build_number()#输出ipa的文件名为当前的build号

)

sigh( #发布打包

clean:true, #打包前clean项目

export_method: "app-store”, #导出方式

scheme:"FloatingWindow_Demo", #scheme

configuration: “Release”,#环境

output_directory:"./app",#ipa的存放目录

output_name:get_build_number()#输出ipa的文件名为当前的build号

)

#firim的配置 替换为自己的api_key和user_key

firim(firim_api_token: “xxxxxxxxxxxx”)

end

《3》在工作目录的终端执行命令:

fastlane test2 desc:测试firim打包

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。