iOS uses fastlane one-click packaging review

Undoubtedly, Jenkins is still very helpful for our packaging - the days when the tested classmates are chasing the IPA package are finally gone. But as a development that pursues efficiency, can we just be satisfied with this? Think about the many other similar problems we encountered in iOS development.


The team members accidentally Revoke the certificate, so all the developers need to re-download the certificate. Every time you submit the App Store review, you need to repeat a series of actions such as [Modify Certificate] - [Package] - [iTunes Connect] - [Release]. It's tiresome and maddening. At this time, fortunately, Fastlane is here, let's see how he comes to save us. Before starting our tutorial, let me clarify what fastlane is not:


  • fastlane is not a tool, but a collection of tools. For example, the match tool can manage certificates, and the deliverer can submit APPStore review. So when we use fastlane, we deal more with its toolset.

  • The tools inside fastlane are not newly written, but the commands that call the mac itself, but it is just automated. For example, the gym tool is just a package of the xcodebuild tool. If you know xcodebuild, then the gym is a piece of cake for you.

  • fastlane itself does not have a set of special syntax, the Ruby language used, I believe that students who have used cocoapods should be easy to use.


After installing fastlane and calling fastlane init, the directory structure looks like this:



The specific installation and initialization will be described in detail later in this article. Let us first analyze the directory structure of fastlane after installation. The red area is the extra file.


  • Gemfile tells us the gems and versions that fastlane depends on, and other information. This is not much related to the topic of this article, and the author will not describe it in detail.

  • The Appfile in the fastlane folder also knows from the file, which contains the information about the App; Fastfile is the main file of fastlane, in which the order and method of each tool we need to use can be written.


Here we first look at the content of a fastlane that has been written:


default_platform(:ios)


platform :ios do

  desc "Description of what the lane does"

  lane :custom_lane do

    # add actions here: https://docs.fastlane.tools/actions

    match(

        git_url: "https://github.com/zjh171/fastlaneProvingProfile",

        type: "appstore" ,

        readonly: true

        )

    gym(

        scheme:"Wallpaper",

        export_method:"app-store",

        output_directory:"./build",

        archive_path:"./Archive"

        )

  end

end


Here we only need to focus on the two tools match and gym and the content after the parentheses. The match tool is the tool we described at the beginning of this article for synchronizing the development partner certificate, while the gym is the package of the xcodebuild tool, which specifies the package directory and package type. After saving the file and executing fastlane custom_lane we can see



This indicates that the App Store package we hit has been generated. The directory is the directory corresponding to the output_directory we specified. Of course, it is not difficult for everyone to guess that if we want fastlane to automatically submit to the App Store for review, we need to add the tools we need after gym. I'll sell it here first, and I'll tell you later. The following author will introduce the use of fastlane in detail.


Install


执行命令sudo gem install fastlane --verbose即可,安装完成后检查一下是否安装成功输入fastlane --version看是否有版本号显示。


初始化


输入命令fastlane init会看到如下选项


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


这四个选项的意思是


  1. 自动截屏。这个功能能帮我们自动截取APP中的截图,并添加手机边框(如果需要的话),我们这里不选择这个选项,因为我们的项目已经有图片了,不需要这里截屏。

  2. 自动发布beta版本用于TestFlight,如果大家有对TestFlight不了解的,可以参考王巍写的这篇文章

  3. 自动的App Store发布包。我们的目标是要提交审核到APP Store,按道理应该选这个,但这里我们先不选,因为选择了以后会需要输入用户名密码,以及下载meta信息,需要花费一定时间,这些数据我们可以后期进行配置。

  4. 手动设置。


选择第四个后一路回车即可,我们会看到生成了我们熟悉的fastlane目录,该目录下包含了Appfile和Fastfile。我们打开这两个文件。


Appfile


# app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app

# apple_id("[[APPLE_ID]]") # Your Apple email address


# For more information about the Appfile, see:

#     https://docs.fastlane.tools/advanced/#appfile


发现里面没有任何信息(“#”在ruby里是注释,所以里面没有任何信息)注释的部分中,app_identifier用于指定APP的bundle id,apple_id指的是你的AppleID。


Fastfile


# Uncomment the line if you want fastlane to automatically update itself

# update_fastlane

default_platform(:ios)

platform :ios do

  desc "Description of what the lane does"

  lane :custom_lane do

    # add actions here: https://docs.fastlane.tools/actions

  end

end


这个文件的信息稍微多一点,而且我们也更熟悉了,语法跟cocoapods很像,而且我们在文章开头已经稍微做了一些介绍,发现在lane :custom_lane do后面是空的。其实意思也就是说,这里任何操作都没有执行。


运行


虽然这是个什么都没有做的fastlane项目,但其实我们可以运行了,执行fastlane custom_lane命令,我们可以看到如下输出


fastlane detected a Gemfile in the current directory however it seems like you don't use `bundle exec` to launch fastlane faster, please use

 $ bundle exec fastlane custom_lane

//此处省略多行

fastlane.tools finished successfully


大致意思就是,我们可以使用命令bundle exec fastlane custom_lane代替fastlane custom_lane,这样会执行的更快。最后的fastlane.tools finished successfully表示执行成功了。


打包


提交审核的前一步是打包,也是最主要的一步fastlane中有专门用于编译、打包的命令gym,我们加到lane :custom_lane do后看看会不会有问题。



然后执行fastlane custom_lane我们会收到如下提示


Select Scheme:

1. Wallpaper

2. AFNetworking

3. Mangogo

4. Masonry

5. MJRefresh

6. Pods-Wallpaper

?


毫无疑问我们选择1,其他的都是我们调用的三方库。但聪明的读者肯定在想,这个Scheme是否能在fastlane文件中就设置好,省的这里在自己选择。是的,这就是文章开头提到的


gym(

    scheme:"Wallpaper",

    export_method:"app-store",

    output_directory:"./build",

    archive_path:"./Archive"

    )


中scheme:"Wallpaper",的含义。其他的参数也就不一一赘述了。读到这里,相信大部分读者已经对fastlane的原理一清二楚了。其实所谓的会用fastlane也就是会用里面的各种工具而已。我相信大家选完Scheme后还没到打包这一步,应该已经出现了错误提示,错误应该就是大家都非常熟悉的证书问题;当然,如果读者够侥幸,证书已经设置好了,并将output_directory、archive_path设置好了,那就能生成对应的对应的IPA包。但相信成功的读者应该寥寥无几,这个时候就要使出我们的大杀器match


证书管理


fastlane中能管理证书和签名的工具其实还有sigh以及cer,那为何笔者要给大家推荐match呢,原因已经在文章开头指出了,对于多人开发时出现的证书错乱问题match可以很好的处理。它将开发人员的证书提交到一个git仓库进行集中处理,在有新的成员加入开发时候,只需要运行一两条命令。下面我就详细讲一下其实现过程吧:


1.创建一个仓库(空仓库或者现有仓库都可以,但建议大家使用一个空仓库专门处理证书),这里笔者的仓库地址是:https://github.com/zjh171/fastlaneProvingProfile

2.在终端运行fastlane match init可以看到需要我们输入giturl地址,我们将地址拷进来即可。



输入地址后我们会看到如下提示


You can now run `fastlane match development`, `fastlane match adhoc`, `fastlane match enterprise` and `fastlane match appstore


我们按照提示生成development和App Store证书,然后会在Xcode中发现生成的证书以及Provision Profile文件。我们在Xcode中设置好即可。



接下来,我们将match添加到fastlane文件中,如下



当然,这个文件我们已经在文章开头看过了,是不是再次感觉豁然开朗。回到命令行,我们再次执行fastlane custom_lane发现我们可爱的IPA包已经打包完毕。


提交App Store审核


终于到了最令人激动的提交App Store时刻了。我们要使用的工具是deliver。聪明的你应该已经知道,第一步肯定是要调用fastlane deliver init,这里会让我们输入APPle ID,输入以后就看到我们的项目文件夹发生了变化:



接着,我们修改一下fastfile文件,添加deliver,因此我们最终版的fastlane文件是这样的:


lane :release do

      # 增加build版本号

    increment_build_number

    match(

        git_url: "https://github.com/zjh171/fastlaneProvingProfile",

        type: "appstore" ,#can be appstore,adhoc, development,enterprise

        app_identifier:"cn.kyson.wallpaper",

        username:"[email protected]",

        readonly: true

        )

    # 编译代码

    gym(

        scheme:"Wallpaper",

        export_method:"app-store",

        )

    # 发布到Apple Store

    deliver

  end


可以看到,大部分配置跟以前一样,只做了lane名的改变,还有添加了increment_build_number这一行。increment_build_number的作用是防止本地版本的build号比App Store(或上次)低而做的自动增长版本号的处理。当然加了这几句还需要在Xcode中做相应处理:



最后在命令行中输入fastlane release,等待大概十几分钟就可以看到成功的提示了。然后我们进入iTunes Connect,确认一下:



确实是已经在审核状态。如果大家想实现“一键审核”可以给deliver带上参数submit_for_review。这样就真正实现了一键提交App Store审核。至此,我们的一键打包审核流程完美收工。


注意点


笔者从开始研究fastlane到完全跑出来大概花了三天时间,期间遇到了很多问题,走了很多弯路,总结一下,希望对读者有一定帮助


  • fastlane的初始化命令是fastlane init,不需要加root权限,也就是sudo fastlane init是不需要的,如果使用了sudo会对后面的各个操作造成很大影响,比如项目文件(workspace后project文件)会锁定不能操作,还会引起打包失败

  • 很多刚接触fastlane的同学会一不注意就被fastlane上的各种命令整的晕头转向,例如sync_code_signing命令,其实是match命令的另外一种写法;build_app命令其实是gym的别名。因此大家在学习fastlane的时候只需要学习本文介绍的命令,大部分情况下已经够用。如果对一个命令的用法不熟悉,可以通过fastlane action查找,例如fastlane action match。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324720262&siteId=291194637