fastlane使用】_我从使用fastlane中学到的6课

fastlane使用】

Personally, I would recommend using Fastlane for anyone involved in iOS development. Once you get the hang of it, it can save you a tremendous amount of time. Setting it up isn’t that hard, but it might be helpful getting some pointers on setting it up right. Here are some pointers to help you get started or to help you improve your setup.

就个人而言,我建议对iOS开发相关人员使用Fastlane 。 一旦掌握了它,就可以节省大量时间。 设置起来并不难,但是获得一些正确设置的指导可能会有所帮助。 这里有一些指针可以帮助您入门或改善设置。

简要回顾 (A Small Recap)

In case you are not familiar with Fastlane, it’s a toolchain that uses the Xcode command line toolchain to automate a vast number of tasks. Most importantly, it allows you to build, test, sign, and upload your app versions without much effort.

如果您不熟悉Fastlane,则它是一个使用Xcode命令行工具链自动执行大量任务的工具链。 最重要的是,它使您可以轻松构建,测试,签名和上传应用程序版本。

The tools are mostly written in Ruby and can be set up through several configuration files, the main one being the Fastfile. In this file, you specify lanes. Each lane runs one or more commands that you would like to group and automate.

这些工具主要是用Ruby编写的,可以通过几个配置文件进行设置,主要的是Fastfile 。 在此文件中,指定车道。 每个通道都运行一个或多个要分组和自动化的命令。

正确管理您的Ruby环境 (Properly Manage Your Ruby Environment)

For most iOS developers, Ruby is not your friend. But since we’re stuck with it, we’d better make the most of it. One of the common issues is using the Ruby system installation to install gems. This is a bad idea because you don’t own that Ruby environment, and there’s no guarantee the OS won’t break your stuff during software updates or reboots.

对于大多数iOS开发人员而言,Ruby不是您的朋友。 但是,由于我们坚持使用它,因此最好充分利用它。 常见问题之一是使用Ruby系统安装来安装gem。 这是一个坏主意,因为您不拥有该Ruby环境,并且不能保证该操作系统不会在软件更新或重新引导期间破坏您的东西。

Then there’s the sudo issue.

然后是sudo问题。

Using sudo for any command should only be done if you’re sure that’s actually needed. Installing gems using sudo means files and folders will be created as the root user, meaning accessing them will also require sudo, etc., etc. Down the rabbit hole you go.

仅在确定确实需要时才应对任何命令使用sudo 。 使用sudo安装gems意味着将以root用户身份创建文件和文件夹,这意味着访问它们也将需要sudo等,等等。

There are several ways to set up your own Ruby environment to prevent this. I highly recommend using either RVM or rbenv. My personal preference is RVM, but using either of these tools helps you keep your environment simple and easy to maintain.

有几种方法可以设置您自己的Ruby环境来防止这种情况。 我强烈建议使用RVMrbenv 。 我个人比较喜欢RVM,但是使用这两种工具中的任何一种都可以帮助您保持环境的简单和易于维护。

“RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.”— rvm.io

“ RVM是一个命令行工具,可让您轻松安装,管理和使用从解释程序到宝石集合的多个Ruby环境。” — rvm.io

It’s really as simple as that. Follow the installation instructions and make sure to avoid using sudo.

就这么简单。 请遵循安装说明,并确保避免使用sudo

使用Bundler管理您的宝石 (Use Bundler to Manage Your Gems)

Image for post

Just as RVM manages your Ruby environment, Bundler can help you manage your gems in a more localised and maintained way. Think of it as CocoaPods for Ruby gems: You can specify exactly which version of dependencies you want to use. In fact, since CocoaPods is also a Ruby gem, you can manage it the same way. Pretty “Inception”-like, right? Honestly, I’m a bit surprised more developers don’t use Bundler for Cocoapods, either.

就像RVM管理您的Ruby环境一样, Bundler可以帮助您以更本地化和更维护的方式管理您的gem。 将其视为Ruby gems的CocoaPods:您可以确切指定要使用的依赖版本。 实际上,由于CocoaPods还是Ruby宝石,因此可以用相同的方式进行管理。 很像“盗梦空间”,对吗? 老实说,令我惊讶的是,更多的开发人员也没有将Bundler用于Cocoapods。

Using Bundler allows you to do two things:

使用Bundler,您可以做两件事:

  • Use different versions of gems for different projects

    对不同的项目使用不同版本的gem
  • Ensure developers (and build servers) use the same versions of gems

    确保开发人员(和构建服务器)使用相同版本的gem

Although it’s rare, I’ve come across strange issues regarding runtime crashes and codesigning problems because the wrong version of a gem was used. Creating a Gemfile takes minutes, and is very similar to having a Podfile in your repo. Then, instead of running pod install , you simple use Bundler to make sure you’re using the local version by calling bundle exec pod install or bundle exec fastlane release for your Fastlane release lane.

尽管很少见,但由于使用了错误的gem版本,因此遇到了有关运行时崩溃和代码签名问题的奇怪问题。 创建Gemfile需要花费几分钟,并且与您的存储库中包含Podfile非常相似。 然后,您无需运行pod install ,而只需使用Bundler来通过调用Fastlane发行版的bundle exec pod installbundle exec fastlane release来确保使用本地版本。

指定要使用的Xcode版本 (Specify Which Version of Xcode You Want to Use)

Image for post

Is your team not ready to update to the latest Xcode yet? You can download and install multiple versions side-by-side. Just rename the .app file and place it next to the others in your Applications folder. This works great for the app, but the command-line tools used by Fastlane need to know which version of Xcode to use.

您的团队还没有准备好更新到最新的Xcode吗? 您可以并行下载和安装多个版本。 只需重命名.app文件,然后将其放置在Applications文件夹中的其他文件旁边。 这对于该应用程序非常有用,但是Fastlane使用的命令行工具需要知道要使用哪个版本的Xcode。

Using the xcode-select command, you can specify which version of Xcode you expect to be using. Fastlane has an action built in to leverage this. This again prevents you from running into nasty issues because the version of Xcode was updated behind your back.

使用xcode-select命令,可以指定期望使用的Xcode版本。 Fastlane具有内置操作来利用这一点。 这再次防止您遇到麻烦的问题,因为Xcode的版本已在背后更新。

If the version is installed and in the right place, Fastlane will find it for you. If not, it’ll fail, stop the build, and tell you what happened.

如果已安装该版本并且在正确的位置,Fastlane会为您找到它。 如果没有,它将失败,停止构建,并告诉您发生了什么。

不要忘记签出Fastlane.Swift (Don’t Forget to Check Out Fastlane.Swift)

Image for post

It’s not as far along as the regular Fastlane, but it might be good enough for your needs. Quite frankly, it also prevents you from getting stuck figuring out the Ruby syntax of a Fastfile. Instead, you can enjoy beautiful Swift syntax and code completion from Xcode. It’s still in beta, but in my endeavours, I rarely bumped into issues because of that. There’s documentation available, and it’s extensive enough to get started.

它不像常规的Fastlane那样远,但是对于您的需求而言可能就足够了。 坦率地说,它还可以防止您弄清楚Fastfile的Ruby语法。 相反,您可以从Xcode享受漂亮的Swift语法和代码完成。 它仍处于测试阶段,但由于我的努力,我很少因此遇到任何问题。 有可用的文档 ,并且内容足够广泛,可以开始使用。

Don’t worry though: If you do get stuck, reverting back to the Ruby version is not too much work. After all, all the commands available in the Swift version are right there. It just might take some time getting used to that Ruby syntax again.

不过,请不要担心:如果您确实遇到困难,那么恢复到Ruby版本并不需要太多工作。 毕竟,Swift版本中所有可用的命令都在那里。 可能需要一些时间才能再次习惯该Ruby语法。

花点时间正确设置钥匙串 (Take Your Time Setting Up the Keychain Correctly)

Every iOS developer remembers the struggles when they first started developing iOS apps and they had to sign their first app. The process has become much simpler over the years, but when building and signing an app on a build server, it’s not always as straightforward as you’d like it to be.

每个iOS开发人员都记得他们刚开始开发iOS应用程序时遇到的困难,他们必须签署自己的第一个应用程序。 这些年来,该过程变得更加简单,但是在构建服务器上构建和签名应用程序时,它并不总是像您希望的那样简单。

使用比赛 (Use Match)

Fastlane provides us with a tool called Match, which will simplify codesigning and sharing certificates with your development team. Basically, Match will take over managing your certificates for you, storing them in a centralised place. When using this tool, you and your team will share one set of credentials, making onboarding new users and renewing certificates much easier.

Fastlane为我们提供了一个名为Match的工具,该工具将简化代码签名并与您的开发团队共享证书。 基本上,Match将接管您的证书管理工作,并将它们存储在集中的位置。 使用此工具时,您和您的团队将共享一组凭据,从而使新用户入职和证书更新更加容易。

从远程连接签名 (Signing from a remote connection)

There might be reasons you can’t or don’t want to use this. Or maybe you simply haven’t made the time to change your process yet. What’s more, code signing errors are cryptic, especially when they occur using the command line.

可能由于某些原因您不能或不想使用它。 或者,也许您只是还没有时间更改流程。 此外,代码签名错误是隐性的,尤其是在使用命令行发生时。

One error I came across more than once is this one:

我多次遇到的一个错误是此错误:

security error -25308
Error: 0xFFFF9D24 -25308 User interaction is not allowed.

This happens because the keychain that is unlocked by default in a regular session (i.e., logged in to the machine as usual) is actually locked when logging in remotely through SSH.

发生这种情况的原因是,通过SSH远程登录时,默认情况下在常规会话中默认解锁的钥匙串(即照常登录到计算机)实际上已被锁定。

Lucky for us, Fastlane has a unlock_keychain command that fixes exactly that. Run this before trying to build/sign your app, and you should be good to go!

对我们来说幸运的是,Fastlane拥有一个完全可以解决该问题的unlock_keychain命令。 在尝试构建/签名应用之前运行此命令,您应该一切顺利!

使用Fastlane尽快构建和交付每个TestFlight构建 (Use Fastlane to Build and Deliver Every TestFlight Build As Soon As Possible)

This one may sound trivial, but it’s easy to postpone this the moment you get stuck on some other task that may need your attention. Once you have this set up, it will not only save you the most time, but you will also notice you’re delivering intermediate test versions much more often, meaning faster feedback and happier testers.

这听起来有些微不足道,但是很容易在您陷入其他可能需要引起注意的任务时将其推迟。 设置完成后,不仅可以节省最多的时间,而且您还会注意到,您将更频繁地交付中间测试版本,这意味着更快的反馈和更快乐的测试人员。

The moment you have this up and running is also the moment you realise you should have automated your builds much sooner. Also, now the next steps to automating more of your process are suddenly within reach.

启动并运行的那一刻,也是您意识到应该更快地自动化构建的那一刻。 而且,现在突然可以实现使更多过程自动化的下一步。

Thanks for reading! Have suggestions or additions? Be sure to let me know!

谢谢阅读! 有建议或补充吗? 一定要让我知道!

翻译自: https://medium.com/better-programming/6-lessons-i-learned-from-using-fastlane-cb35f53021b3

fastlane使用】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值