打包和发布到 iOS 平台

这个教程将为你提供关于如何将 Flutter App 发布到 App StoreTestFlight 的说明。

This guide provides a step-by-step walkthrough of releasing a Flutter app to the App Store and TestFlight.

关于混淆 Dart 代码的更多信息,你可以看 混淆 Dart 代码

For information on obfuscating Dart code, see Obfuscating Dart Code.

预先准备

Preliminaries

在开始发布你的 app 的进程之前,确保你已经看过了 Apple 的 App Store 审核指南

Before beginning the process of releasing your app, ensure that it meets Apple’s App Review Guidelines.

想要发布你的 app 到 App Store,你需要注册 Apple Developer Program。你可以在苹果的 选择会员资格(开发者类型) 中查看到关于多种不同会员类型的选择。

In order to publish your app to the App Store, you’ll need to enroll in the Apple Developer Program. You can read more about the various membership options in Apple’s Choosing a Membership guide.

在 App Store Connect 上注册你的 App

Register your app on App Store Connect

App Store Connect(曾经的 iTunes Connet)是你将会管理应用生命周期的地方。你将会定义应用的名称和描述以及截图,设置价格,并管理发布到 App Store 和 Testflight。

App Store Connect (formerly iTunes Connect) is where you’ll manage your app’s life cycle. You will define your app name and description, add screenshots, set pricing, and manage releases to the App Store and TestFlight.

注册你的 app 需要两步:登记唯一的套装 ID(Bundle ID),并在你的 App Store Connect 中创建一个 app。

Registering your app involves two steps: registering a unique Bundle ID, and creating an application record on App Store Connect.

关于更多 App Store Connect 的细节,查看 App Store Connect 指南。

For a detailed overview of App Store Connect, see the App Store Connect guide.

登记套装 ID

Register a Bundle ID

每一个 iOS 应用都与一个在 Apple 登记的唯一的套装 ID 关联。要为你的应用登记一个套装 ID,请参考下面的步骤:

Every iOS application is associated with a Bundle ID, a unique identifier registered with Apple. To register a Bundle ID for your app, follow these steps:

  1. 在你的开发者账号页面打开 App IDs 页面。

    Open the App IDs page of your developer account.

  2. 点击 + 来创建一个新的套装 ID。

    Click + to create a new Bundle ID.

  3. 输入一个 App 名称,选择 Explicit App ID,然后输入一个 ID。

    Enter an app name, select Explicit App ID, and enter an ID.

  4. 选择你的 App 将要使用的服务,然后点击 继续

    Select the services your app will use, then click Continue.

  5. 在下一页,确认细节并点击 注册 来注册你的 Bundle ID。

    On the next page, confirm the details and click Register to register your Bundle ID.

在 App Store Connect 创建一个应用记录

Create an application record on App Store Connect

接下来,你需要在 App Store Connect 注册你的应用:

Next, you’ll register your app on App Store Connect:

  1. 在你的浏览器里打开 App Store Connect

    Open App Store Connect in your browser.

  2. 在 App Store Connect 的落地页,点击 My Apps

    On the App Store Connect landing page, click My Apps.

  3. 在我的 app 页面的顶部左侧,点击 + ,然后选择 New App

    Click + in the top-left corner of the My Apps page, then select New App.

  4. 在出现的表单中填写你的 app 细节。在平台部分,确保 iOS 被选中。由于 Flutter 暂时不支持 tvOS,保持该选项为未选。点击 Create

    Fill in your app details in the form that appears. In the Platforms section, ensure that iOS is checked. Since Flutter does not currently support tvOS, leave that checkbox unchecked. Click Create.

  5. 跳转到你的应用详情,然后从侧边栏选择 App Information

    Navigate to the application details for your app and select App Information from the sidebar.

  6. 在基础信息部分,选择你在前一步注册的套装 ID。

    In the General Information section, select the Bundle ID you registered in the preceding step.

想要获取更多信息,可以看这个帮助页面 添加 App 至您的帐户

For a detailed overview, see Add an app to your account.

检查 Xcode 项目设置

Review Xcode project settings

在这一步,你需要在 Xcode 工作空间检查绝大多数重要设置。关于更多的步骤和描述,查看 为 App 分发做准备

In this step, you’ll review the most important settings in the Xcode workspace. For detailed procedures and descriptions, see Prepare for app distribution.

在 Xcode 中跳转到你的目标设置:

Navigate to your target’s settings in Xcode:

  1. 在 Xcode 中,打开你的 App 的 ios 目录中的 Runner.xcworkspace

    In Xcode, open Runner.xcworkspace in your app’s ios folder.

  2. 想要看你的 app 设置,在 Xcode 的项目导航栏中选择 Runner

    To view your app’s settings, select the Runner project in the Xcode project navigator. Then, in the main view sidebar, select the Runner target.

  3. 选择 General tab

    Select the General tab.

接下来,你需要验证最重要的配置:

Next, you’ll verify the most important settings:

在 Identity 部分:

In the Identity section:

  • 这个 App 将会在主屏幕以及其他地方展示的名字。

    Display Name: the name of the app to be displayed on the home screen and elsewhere.

  • 你在 App Store Connect 注册的 App ID。

    Bundle Identifier: the App ID you registered on App Store Connect.

在 Signing 部分:

In the Signing section:

  • Automatically manage signing 是否需要 Xcode 自动管理 app 签名和设置。这个默认被设置为 true ,对于绝大多数 App 来说都是适用的。对于更复杂的场景,查看 代码签名指南

    Automatically manage signing: whether Xcode should automatically manage app signing and provisioning. This is set true by default, which should be sufficient for most apps. For more complex scenarios, see the Code Signing Guide.

  • Team:选择关联到你注册的 Apple 开发者账户的团队。如果需要,选择 Add Account…, 然后更新选项。

    Team: select the team associated with your registered Apple Developer account. If required, select Add Account…, then update this setting.

在 Development 部分:

In the Deployment Info section:

  • Deployment Target: 你的 App 将会支持的最低版本的 iOS。 Flutter 支持 iOS 8.0 及以后的版本。如果你的 App 包含使用了iOS 8 不支持的 API 的 Objective-C 或 Swift 代码,请设置到合适的版本。

    Deployment Target: the minimum iOS version your app will support. Flutter supports iOS 8.0 and later. If your app includes Objective-C or Swift code that makes use of APIs that were unavailable in iOS 8, update this setting appropriately.

你项目的 General tab 应该看起来像是这样的:

The General tab of your project settings should resemble the following:

Xcode Project Settings

更多关于 App 签名新的介绍,查看 创建, 导出, 和删除签名证书

For a detailed overview of app signing, see Create, export, and delete signing certificates.

添加应用图标

Add an App Icon

当你创建一个新的 Flutter 应用时,则会创建一个默认的图标。在这一步,你将使用你自己的图标替换占位图标:

When a new Flutter app is created, a placeholder icon set is created. In this step, you’ll replace these placeholder icons with your app’s icons:

  1. 回顾 iOS 的 App Icon 指南。

    Review the iOS App Icon guidelines.

  2. 在 Xcode 项目导航栏,选择 Runner 目录中的 Assets.xcassets,更新占位图标为你自己的 app 的图标。

    In the Xcode project navigator, select Assets.xcassets in the Runner folder. Update the placeholder icons with your own app icons.

  3. 通过执行 flutter run 来验证你的图标是否已经被替换。

    Verify the icon has been replaced by running your app using flutter run.

创建一个构建归档(build archive)

Create a build archive

在这一步,你将创建一个构建归档,并上传到 App Store Connect。

In this step, you’ll create a build archive and upload your build to App Store Connect.

在开发过程中,你将会使用 debug 模式来完成构建、调试并测试。当你准备好通过 App Store 或 TestFlight 交付你的 app 给用户时,你需要准备一个 release 构建。

During development, you’ve been building, debugging, and testing with debug builds. When you’re ready to ship your app to users on the App Store or TestFlight, you’ll need to prepare a release build.

在命令行中你的应用目录下执行如下步骤:

On the command line, follow these steps in your application directory:

  1. 执行 flutter build ios 来创建一个 release 构建 (flutter build 默认指向 --release)。

    Run flutter build ios to create a release build (flutter build defaults to --release).

  2. 为了确保 Xcode 刷新了发布模式的配置,关闭并重新打开你的 Xcode。对于 Xcode 8.3 及以后版本,这一步不是必须的。

    To ensure that Xcode refreshes the release mode configuration, close and re-open your Xcode workspace. For Xcode 8.3 and later, this step is not required.

在 Xcode中,配置 app 的版本,并开始构建:

In Xcode, configure the app version and build:

  1. 在 Xcode 中,打开你应用 ios 目录中的 Runner.xcworkspace

    In Xcode, open Runner.xcworkspace in your app’s ios folder.

  2. 选择 Product > Scheme > Runner

    Select Product > Scheme > Runner.

  3. 选择 Product > Destination > Generic iOS Device

    Select Product > Destination > Generic iOS Device.

  4. 在 Xcode 项目导航栏中选择 Runner,然后在设置界面侧边栏选择 Runner 目标。

    Select Runner in the Xcode project navigator, then select the Runner target in the settings view sidebar.

  5. 在 Identity 部分,更新 Version 为你想要发布的用户可见的版本号。

    In the Identity section, update the Version to the user-facing version number you wish to publish.

  6. 在 Identity 部分,更新 Build 标示为一个唯一的 Build 数字,用来在 App Store Connect 上追踪。每一个上传都需要一个独立的 Build 数字。

    In the Identity section, update the Build identifier to a unique build number used to track this build on App Store Connect. Each upload requires a unique build number.

最后,创建一个构建归档并将其上传到 App Store Connect:

Finally, create a build archive and upload it to App Store Connect:

  1. 选择 Product > Archive 来生成一个构建归档

    Select Product > Archive to produce a build archive.

  2. 在 Xcode 组织界面的侧边栏中,选择你的 iOS app,然后选择你刚刚的生成的构建归档。

    In the sidebar of the Xcode Organizer window, select your iOS app, then select the build archive you just produced.

  3. 点击 Validate… 按钮。如果报告了任何问题,记录下他们并重新开始一个新的构建。你可以使用同一个 Build ID 直到你上传了一个归档。

    Click the Validate… button. If any issues are reported, address them and produce another build. You can reuse the same build ID until you upload an archive.

  4. 当这个归档校验成功以后,点击 Upload to App Store…。你可以在 App Store Connect 中应用详情页面的 Activities 标签页查看你的构建状态。

    After the archive has been successfully validated, click Upload to App Store…. You can follow the status of your build in the Activities tab of your app’s details page on App Store Connect.

当你的构建已经通过了校验,可以将你的构建通过 Testfligh 发布给你的测试人员或直接将其发布到 App Store 的时候,你会在 30 分钟内收到一封信来提醒你。

You should receive an email within 30 minutes notifying you that your build has been validated and is available to release to testers on TestFlight. At this point you can choose whether to release on TestFlight, or go ahead and release your app to the App Store.

更多信息可以查看 上传一个 App 到 App Store Connect (Upload an app to App Store Connect)

For more details, see Upload an app to App Store Connect.

发布你的 app 到 TestFlight

Release your app on TestFlight

TestFlight 允许开发者发布他们的 app 给内部或外部的测试人员。这个步骤为可选,接下来的内容将引导你将发布你的构建到 TestFlight。

TestFlight allows developers to push their apps to internal and external testers. In this optional step, you’ll release your build on TestFlight.

  1. App Store Connect中,你的应用的详情页面跳转到 TestFlight Tab。

    Navigate to the TestFlight tab of your app’s application details page on App Store Connect.

  2. 在侧边栏选择 Internal Testing

    Select Internal Testing in the sidebar.

  3. 选择要发布给测试人员的构建,然后点击 保存

    Select the build to publish to testers, then click Save.

  4. 为每一个内部测试人员添加邮件。你可以在 App Store Connect 的用户与角色页面添加额外的内部用户,他们将会出现在页面顶部的下拉菜单中。

    Add the email addresses of any internal testers. You can add additional internal users in the Users and Roles page of App Store Connect, available from the dropdown menu at the top of the page.

关于更多信息,请查看 使用 TestFlight 分发应用 (Distribute an app using TestFlight (iOS, tvOS, watchOS) )

For more details, see Distribute an app using TestFlight.

发布你的 app 到 App Store

Release your app to the App Store

当你准备发布你的 app 到这个世界时,跟随下面的步骤,来提交你的 App 去审核,并将其发布到 App Store。

When you’re ready to release your app to the world, follow these steps to submit your app for review and release to the App Store:

  1. 从你的 app 在 App Store Connect 的页面中的侧边栏中选择 Pricing and Availability,然后完善所有的必填信息。

    Select Pricing and Availability from the sidebar of your app’s application details page on App Store Connect and complete the required information.

  2. 从侧边栏选择状态。如果这是第一次发布这个 App,这个状态将会是 1.0 Prepare for Submission,填写所有需要填写的区域。

    Select the status from the sidebar. If this is the first release of this app, its status will be 1.0 Prepare for Submission. Complete all required fields.

  3. 点击 提交审核

    Click Submit for Review.

Apple 将会在他们的审核过程结束后提醒你。你的 app 将会根据 Version Release 部分的介绍进行发布。

Apple will notify you when their app review process is complete. Your app will be released according to the instructions you specified in the Version Release section.

关于更多细节,查看 通过 App Store 分发一个 App.

For more details, see Distribute an app through the App Store.

故障排除

Troubleshooting

分发你的 app 指南提供了一个详细的关于发布一个 App 到 App Store 过程的内容。

The Distribute your app guide provides a detailed overview of the process of releasing an app to the App Store.