快速集成 Flutter Shorebird 热更新

Flutter Shorebird 是一种云端代码推送服务,可以让开发者在几分钟内集成,无需修改代码即可将更新推送到任何 Dart 代码,支持所有 Android 和 iOS 设备,并符合 App Store 和 Play Store 的规定。Shorebird 最大的优点是无代码侵入,快速集成,设计优秀。

快速集成 Flutter Shorebird 热更新

flutter shorebird

视频

https://youtu.be/0rBst-AB6_0

https://www.bilibili.com/video/BV1Bt421K7Mf

前言

原文 https://ducafecat.com/blog/flutter-shorebird-push-code-hot-updates-quickstart-guide

Flutter Shorebird 是一种云端代码推送服务,可以让开发者在几分钟内集成,无需修改代码即可将更新推送到任何 Dart 代码,支持所有 Android 和 iOS 设备,并符合 App Store 和 Play Store 的规定。Shorebird 最大的优点是无代码侵入,快速集成,设计优秀。

图片中显示的是手动更新补丁,而不是自动更新。

自动更新用户是无感的。

Flutter, Shorebird, 代码推送, 热更新, Flutter热更新

参考

https://shorebird.dev/

https://docs.shorebird.dev/

知识点

发布与补丁对应

release path

使用顺序

shorebird use

第一步:注册、安装

关联 google 账号

https://console.shorebird.dev/login

管理你的 google , 热更新二进制文件将会上传到 google cloud。

安装 shorebird 命令 cli

macos

curl --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/shorebirdtech/install/main/install.sh -sSf | bash

windows

Set-ExecutionPolicy RemoteSigned -scope CurrentUser # Needed to execute remote scripts
iwr -UseBasicParsing 'https://raw.githubusercontent.com/shorebirdtech/install/main/install.ps1'|iex

检查环境

> shorebird doctor

Shorebird 1.1.6 git@github.com:shorebirdtech/shorebird.git
Flutter 3.22.0 revision 6d047e401941206daf11740c523ffa3364a2385b
Engine revision c600950be82dcdad6a46da46bcc6e73773ca3907

 Shorebird is up-to-date (3.6s)
 Flutter install is correct (1.1s)
  [!] Shorebird does not respect the FLUTTER_STORAGE_BASE_URL environment variable at this time
 Has access to storage.googleapis.com (0.9s)
1 issue detected.

命令行登录

> shorebird login

You are already logged in as <ducafecat@gmail.com>.
Run shorebird logout to log out and try again.

第二步:初始你的项目

环境要求

> flutter --version

Flutter 3.22.0 channel stable https://github.com/flutter/flutter.git
Framework revision 5dcb86f68f (2 周前) • 2024-05-09 07:39:20 -0500
Engine revision f6344b75dc
Tools Dart 3.4.0 DevTools 2.34.3

开发环境需要和 shorebird 一致, flutter sdk 3.22.0

初始你的项目

> shorebird init

 No product flavors detected. (4.4s)
? How should we refer to this app? (flutter_application_shorebird) flutter_application_shorebird

 Shorebird initialized successfully!

 A shorebird app has been created.
 A "shorebird.yaml" has been created.
 The "pubspec.yaml" has been updated to include "shorebird.yaml" as an asset.

Reference the following commands to get started:

 To create a new release use: "shorebird release".
 To push an update use: "shorebird patch".
 To preview a release use: "shorebird preview".

For more information about Shorebird, visit https://shorebird.dev
 Shorebird is up-to-date (2.9s)
 Flutter install is correct (1.0s)
  [!] Shorebird does not respect the FLUTTER_STORAGE_BASE_URL environment variable at this time
 AndroidManifest.xml files contain INTERNET permission (1 fix applied) (0.1s)
 Has access to storage.googleapis.com (0.7s)
 shorebird.yaml found in pubspec.yaml assets (5ms)

第三步:发布、热更新

编译发布版本

编译 android aab 文件,提交 google 后台

shorebird release android

输出

 shorebird release android 

 Fetching apps (0.9s)
 Building app bundle with Flutter 3.22.0 (6d047e4019) (48.6s)
 Release version: 1.0.0+1 (0.4s)
 Fetching releases (0.8s)

 Ready to create a new release!

 App: flutter_application_shorebird (c204bc07-5755-4e3c-966f-2fcb3f50272f)
 Release Version: 1.0.0+1
  Platform: android
 Flutter Version: 3.22.0 (6d047e4019)

Would you like to continue? (y/N) Yes
 Fetching releases (0.8s)
 Creating release (1.5s)
 Updating release status (0.8s)
 Creating artifacts (33.9s)
 Updating release status (2.5s)

 Published Release 1.0.0+1!
Your next step is to upload the app bundle to the Play Store:
/Users/ducafecat/Desktop/flutter_application_shorebird/build/app/outputs/bundle/release/app-release.aab

For information on uploading to the Play Store, see:
https://support.google.com/googleplay/android-developer/answer/9859152?hl=en

To create a patch for this release, run shorebird patch --platforms=android --release-version=1.0.0+1

Note: shorebird patch --platforms=android without the --release-version option will patch the current version of the app.

编译 android apk 文件,方便内部测试

shorebird release android --artifact apk
> shorebird release android --artifact apk 

 Fetching apps (0.8s)
 Building app bundle with Flutter 3.22.0 (6d047e4019) (7.3s)
 Building APK with Flutter 3.22.0 (6d047e4019) (8.1s)
 Release version: 1.0.0+1 (0.4s)
 Fetching releases (0.7s)
It looks like you have an existing android release for version 1.0.0+1.
Please bump your version number and try again.

You can manage this release in the Shorebird Console

编译 ios 文件

shorebird release ios

xcode 配置好证书

用户安装

通过 adb ,或者平台安装

编译补丁

shorebird patch android

输出

 shorebird patch android 

 Fetching apps (2.0s)
 Building patch with Flutter 3.22.0 (6d047e4019) (6.0s)
 Fetching releases (0.8s)
 Fetching aab artifact (0.8s)
 Downloading aab (5.0s)
 Verifying patch can be applied to release (38ms)
 Fetching release artifacts (2.3s)
 Downloading release artifacts (8.2s)
 Creating patch artifacts (1.5s)

 Ready to publish a new patch!

 App: flutter_application_shorebird (c204bc07-5755-4e3c-966f-2fcb3f50272f)
 Release Version: 1.0.0+1
  Platform: android [arm32 (130 B), arm64 (126 B), x86_64 (122 B)]
 Track: Production

Would you like to continue? (y/N) Yes
 Creating patch (2.5s)
 Uploading artifacts (5.5s)
 Fetching channels (0.8s)
 Promoting patch to stable (0.7s)

 Published Patch 1!

每次都有一个新 patch 编号

自动更新

你重新打开程序后 ,自动更新了程序

第四步:手动热更新(可选)

各种理由我们有时候需要一个选择是否更新的选项,比如测试的时候。

编辑 shorebird.yaml

auto_update: false

设置 false 关闭自动更新

重新编译一个新版本、新补丁 patch

具体参考代码可以看我的 github 代码,我已经跑通,这里就不再详述

https://github.com/ducafecat/flutter_develop_tips/blob/main/flutter_application_shorebird/lib/main.dart

代码

https://github.com/ducafecat/flutter_develop_tips/tree/main/flutter_application_shorebird

小结

Flutter Shorebird 是一个强大的云端代码推送解决方案,可以让开发者在几分钟内集成,无需修改代码即可将更新推送到任何 Dart 代码,支持所有 Android 和 iOS 设备。这种技术不仅能够提高应用的更新效率,还符合 App Store 和 Play Store 的发布要求,是 Flutter 开发者必须了解的重要技术之一。通过结合 Flutter 的跨平台优势和 Shorebird 的云端部署能力,开发者可以更高效地管理和更新他们的应用程序,为用户提供更好的体验。

感谢阅读本文

如果有什么建议,请在评论中让我知道。我很乐意改进。


flutter 学习路径


© 猫哥 ducafecat.com

end