iOS 自动打包 - fastlane

2018-09-19 17:16:49 浏览数 (1)

1 本文只是fastlane的基本使用. 2 使用fastlane前,确保你已经可以使用Xcode手动打包成功(说明你已经配置好证书)

1.配置环境

1.安装HomeBrew

代码语言:javascript复制
#安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

#更新到最新版
brew update

#更新包
brew upgrade

2.安装ruby

代码语言:javascript复制
#安装
brew install ruby

#查看版本
ruby -v  

ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]

3.安装fastlane

代码语言:javascript复制
#安装
sudo gem install fastlane -NV

#查看版本
fastlane -v 

fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.102.0/bin/fastlane
-----------------------------
[✔] ? 
fastlane 2.102.0

配置环境结束,应该没什么难度.

2.使用 fastlane

1.先cd到项目路径

代码语言:javascript复制
cd /Users/yu/Documents/MyApp

2.初始化 fastlane (一个项目的第一次需要)

代码语言:javascript复制
fastlane init 

[✔] ? 
[✔] Looking for iOS and Android projects in current directory...
[17:22:06]: Created new folder './fastlane'.
[17:22:06]: Detected an iOS/macOS project in the current directory: 'Daily.xcworkspace'
[17:22:06]: -----------------------------
[17:22:06]: --- Welcome to fastlane ? ---
[17:22:06]: -----------------------------
[17:22:06]: fastlane can help you with all kinds of automation for your mobile app
[17:22:06]: We recommend automating one task first, and then gradually automating more over time
[17:22:06]: 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

我们选择4,输入4,然后回车就可以了。

代码语言:javascript复制
?  4
[17:22:17]: ------------------------------------------------------------
[17:22:17]: --- Setting up fastlane so you can manually configure it ---
[17:22:17]: ------------------------------------------------------------
[17:22:17]: Installing dependencies for you...
[17:22:17]: $ bundle update

看到上面的输出后,在我们项目路径下已经生成fastlane文件了。 点开发现有2个文件 Appfile 和 Fastfile 2个文件。

Appfile 和 Fastfile.png

3.编写Appfile和Fastfile 文件 Appfile文件

代码语言:javascript复制
# app_identifier("yu.xx.MyApp") # The bundle identifier of your app
# apple_id("appld@outlook.com") # Your Apple email address

# itc_team_id
team_id "43XXXXXX9K" # Developer Portal Team ID


# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile

Fastfile文件

代码语言:javascript复制
# 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_fastlane

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :keji do
    build_app(workspace:"MyApp.xcworkspace",
          scheme:"MyApp",
          export_method:"development",
          output_directory:"./fastlane/ipadFile",
          configuration:"Debug")
  end
end

?注意 查找team_id:在你用Xcode手动打包后,生成的文件中(MyApp 2018-08-17 14-33-14)。ExportOptions.plist这个文件中包含team_id。

4.打包 最后的时候我们执行打包就可以了

代码语言:javascript复制
fastlane MyApp

MyApp是你的项目文件名 显示打包成功后,在MyApp/fastlane/ipadFile中就能看到ipa包了。?

3.扩展

1.ipa自动发布

自动打包成功后,当然需要自动发布到蒲公英,或者fir了。以蒲公英为例子: 1 安装蒲公英的 Fastlane 插件:

代码语言:javascript复制
fastlane add_plugin pgyer

2 修改Fastfile文件

代码语言:javascript复制
default_platform(:ios)
platform :ios do
  desc "Description of what the lane does"
  lane :keji do
    build_app(workspace:"MyApp.xcworkspace",
          scheme:"MyApp",
          export_method:"development",
          output_directory:"./fastlane/ipadFile",
          configuration:"Debug")
    pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e", update_description: "update by fastlane")
  end
end

使用 Fastlane 上传 App 到蒲公英API https://www.pgyer.com/doc/view/fastlane

0 人点赞