找回密码
 会员注册
查看: 23|回复: 0

fastlane自动化打包iOSAPP

[复制链接]

4

主题

0

回帖

13

积分

新手上路

积分
13
发表于 2024-10-11 20:08:00 | 显示全部楼层 |阅读模式
概述APP自动化打包常见的主流工具有Jenkins、fastlane。Jenkins功能强大,但是需要的配置也比较多,团队较大的可以优先考虑,fastlane是用Ruby语言编写的一套自动化工具集,比较轻便,配置简单,使用起来也很方便。本文会详细的介绍fastlane从安装到上传APP到蒲公英的整个流程。fastlane的安装第一步因为fastlane是用Ruby语言编写的工具,所以必须保证已经配置好了Ruby开发环境。可以使用如下命令行查看是否安装了Ruby:ruby -v如果有以下提示说明,你已经安装了Ruby:ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin21]如果没有安装需要先安装ruby,本文对安装ruby不作教程说明。第二步安装Xcode命令行工具xcode-select--install如果没有安装,命令会有提示框,根据提示一步一步安装即可。如果出现以下命令提示,说明已经安装成功:xcode-select: error: command line tools are already installed, use "Software Update" to install updates第三步:Ruby和Xcode环境都配置好之后,执行以下命令来安装fastlane:sudogeminstall-n/usr/local/binfastlane安装完成之后,输入以下命令查看是否安装成功:fastlane --version出现以下提示说明你已经安装成功了:fastlane installation at path:/Users/xxxxxx/.rvm/gems/ruby-2.7.0/gems/fastlane-2.206.1/bin/fastlane-----------------------------[] fastlane 2.206.1fastlane的配置到你的iOS项目下,执行初始化命令:fastlane init命令执行完成之后会给出我们如下几个提示:[] [] Looking for iOS and Android projects in current directory...[16:54:04]: Created new folder './fastlane'.[16:54:04]: Detected an iOS/macOS project in the current directory: 'xxxx.xcworkspace'[16:54:04]: -----------------------------[16:54:04]: --- Welcome to fastlane ---[16:54:04]: -----------------------------[16:54:04]: fastlane can help you with all kinds of automation for your mobile app[16:54:04]: We recommend automating one task first, and then gradually automating more over time[16:54:04]: What would you like to use fastlane for1. Automate screenshots2. Automate beta distribution to TestFlight3. Automate App Store distribution4. Manual setup - manually setup your project to automate your tasks命令执行到最后有What would you like to use fastlane for提示,此时fastlane列出几个选项,需要我们告诉它使用fastlane需要执行哪种操作:第一种获取App Store的App预览照片。第二种打包上传至TestFlight工具上。第三种打包上传到App Store。第四种自定义打包方式。以上四种方式根据自己的需要自行选择,本文主要介绍打包上传至第三方平台,所以选择4自定义打包方式。选择完成之后,fastlane会在我们项目中创建fastlane文件[16:54:32]: ------------------------------------------------------------[16:54:32]: --- Setting up fastlane so you can manually configure it ---[16:54:32]: ------------------------------------------------------------[16:54:32]: Installing dependencies for you...[16:54:32]: $ bundle update[16:54:40]: --------------------------------------------------------[16:54:40]: --- Successfully generated fastlane configuration ---[16:54:40]: --------------------------------------------------------[16:54:40]: Generated Fastfile at path `./fastlane/Fastfile`[16:54:40]: Generated Appfile at path `./fastlane/Appfile`[16:54:40]: Gemfile and Gemfile.lock at path `Gemfile`[16:54:40]: Please check the newly generated configuration files into git along with your project[16:54:40]: This way everyone in your team can benefit from your fastlane setup[16:54:40]: Continue by pressing Enter 创建好fastlane文件夹之后,Appfile是编辑我们相关App和开发者账号信息的,一般不需要我们去手动修改。Fastfile是我们对自动打包这个过程的完整配置,默认的Fastfile文件内容如下:# This file contains the fastlane.tools configuration# You can find the documentation at https://docs.fastlane.tools## For a list of all available actions, check out## https://docs.fastlane.tools/actions## For a list of all available plugins, check out## https://docs.fastlane.tools/plugins/available-plugins## Uncomment the line if you want fastlane to automatically update itself# update_fastlanedefault_platform(:ios)platform :ios do desc "Description of what the lane does" lane :custom_lane do # add actions here: https://docs.fastlane.tools/actions endend打包并自动上传 App 到蒲公英安装蒲公英的 fastlane 插件fastlane add_plugin pgyer编辑Fastlane 的配置文件 fastlane/Fastfilelane :develop do target = "demo" configuration = "Debug" gym(scheme: target, configuration: configuration, export_method:"development") pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")end以下是蒲公英平台的说明:以上的 api_key 和 user_key,请开发者在自己账号下的 应用管理 - App概述 - API 中可以找到,并替换到以上相应的位置。在 Xcode 8.3 和 Xcode 8.3 以后的版本中,对于 build_app 的 export_method 的值,需要根据开发者的打包类型进行设置,可选的值有:app-store、ad-hoc、development、enterprise。对于 Xcode 8.3 以下的版本,则不需要设置 export_method。经过以上配置后,就可以使用 Fastlane 来打包 App,并自动上传到蒲公英了。在终端下,定位到项目所在目录,输入以下命令即可:fastlane develop在成功的情况下,可以看到类似下面的信息:[18:37:22]: Successfully exported and compressed dSYM file[18:37:22]: Successfully exported and signed the ipa file:[18:37:22]: /Users/xxx/Documents/workCode/xxxxx.ipa[18:37:22]: -------------------[18:37:22]: --- Step: pgyer ---[18:37:22]: -------------------[18:37:22]: The pgyer plugin is working.[18:37:22]: build_file: /Users/dddd/Documents/workCode/xxxx.ipa[18:37:22]: Start upload /Users/dddd/Documents/workCode/xxx.ipa to pgyer...[18:37:43]: Upload success. Visit this URL to see: https://www.pgyer.com/xxxxx+------+------------------+-------------+| fastlane summary |+------+------------------+-------------+| Step | Action | Time (in s) |+------+------------------+-------------+| 1 | default_platform | 0 || 2 | gym | 61 || 3 | pgyer | 20 |+------+------------------+-------------+[18:37:43]: fastlane.tools finished successfully 设置一个版本更新时的描述信息:lane :develop do build_app(export_method: "development") pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e", update_description: "update by fastlane")end打包上传到Testflight在Fastfile文件中加入下面命令:desc "打包上传到Testflight" lane :beta do # add actions here: https://docs.fastlane.tools/actions target = "demo" configuration = "Release" gym(scheme: target, configuration: configuration, export_method:"app-store") upload_to_testflight( username: "xxxx@dd.com", app_identifier: "com.xxxx", )在命令行输入:fastlane beta打包上传的过程中会让你输入苹果账号的密码,并且有可能会报下面的错:[00:20:28]: Login successful[00:20:31]: Ready to upload new build to TestFlight (App: fffff)...[00:20:40]: Transporter transfer failed.[00:20:40]: [00:20:40]: Please sign in with an app-specific password. You can create one at appleid.apple.com. (-22910)[00:20:41]: [00:20:41]: Your account has 2 step verification enabled[00:20:41]: Please go to https://appleid.apple.com/account/manage[00:20:41]: and generate an application specific password for[00:20:41]: the iTunes Transporter, which is used to upload builds[00:20:41]: [00:20:41]: To set the application specific password on a CI machine using[00:20:41]: an environment variable, you can set the[00:20:41]: FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD variable这是因为你的APPLE账号开启了双重验证,注意这句提示Please sign in with an app-specific password用app专用密码登录,提示你创建一个app专用密码登录Transporter,关于怎么创建app专用密码本人不做讲解,可以自行百度或者谷歌,使用app专用账号即可解决此问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2024-12-27 15:12 , Processed in 0.386807 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表