当前位置: 首页 > 工具软件 > fastlane > 使用案例 >

flutter iOS 使用fastlane 打 IPA 包

寿子轩
2023-12-01

如果你是一位flutter开发者,你可能会遇到这样的问题:如何快速地为iOS平台打包IPA文件,并上传到蒲公英或其他分发平台?手动打包的过程不仅耗时,而且容易出错。有没有一种更简单、更高效的方法呢?答案是有的,那就是使用fastlane。

fastlane是一个自动化工具,它可以帮助你完成iOS和Android应用程序的测试、部署和发布等繁琐的任务。它可以处理代码签名、生成屏幕截图、打包IPA文件、上传到分发平台等操作。fastlane是基于Ruby的,所以你需要安装Ruby环境才能使用它。fastlane也支持flutter项目,只需要一些简单的配置,就可以实现flutter项目的自动化打包。

本文将介绍如何使用fastlane为flutter项目打包IPA文件,并上传到蒲公英平台。我们假设你已经有一个flutter项目,并且已经配置好了iOS平台的相关设置,例如证书、描述文件、bundle id等。我们也假设你已经安装了Xcode和CocoaPods,并且可以在Xcode中正常运行你的项目。

首先,你需要在你的项目根目录下创建一个名为fastlane的文件夹,并在其中创建一个名为Fastfile的文件。这个文件是fastlane的核心配置文件,它定义了不同的任务(称为lanes)和它们的执行步骤。你可以根据你的需求自定义不同的lanes,例如测试、打包、发布等。

在Fastfile中,我们需要定义一个名为build_ipa的lane,用于打包IPA文件。这个lane的主要步骤如下:

  1. 使用flutter命令构建iOS项目,并生成Runner.app文件。
  2. 使用gym命令将Runner.app文件打包成IPA文件,并保存到指定的路径。
  3. 使用pilot命令将IPA文件上传到蒲公英平台,并返回下载链接。

具体的代码如下:

default_platform(:ios)

platform :ios do
desc "Build IPA file for flutter project"
lane :build_ipa do
# Build iOS project with flutter command
sh("flutter", "build", "ios", "--release")

# Get the path of Runner.app file
app_path = File.join(Dir.pwd, "build", "ios", "iphoneos", "Runner.app")

# Package IPA file with gym command
gym(
workspace: "ios/Runner.xcworkspace",
configuration: "Release",
scheme: "Runner",
export_method: "ad-hoc",
output_directory: "./build/ipa",
output_name: "Runner.ipa",
clean: true,
silent: true,
skip_package_ipa: false,
export_options: {
provisioningProfiles: {
# Specify the bundle id and the provisioning profile name
"com.example.flutter" => "Flutter Ad Hoc"
}
}
)

# Get the path of IPA file
ipa_path = File.join(Dir.pwd, "build", "ipa", "Runner.ipa")

# Upload IPA file to pgyer platform with pilot command
pilot(
ipa: ipa_path,
distribute_external: false,
skip_submission: true,
skip_waiting_for_build_processing: true,
api_key_path: "./pgyer_api_key.json" # The json file that contains the api key for pgyer platform
)
end
end
 类似资料: