快速集成 Flutter Shorebird 热更新
Flutter Shorebird 是一种云端代码推送服务,可以让开发者在几分钟内集成,无需修改代码即可将更新推送到任何 Dart 代码。支持所有 Android 和 iOS 设备,并符合 App Store 和 Play Store 的规定。Shorebird 最大的优点是无代码侵入,快速集成,设计优秀。
官网
Welcome | Shorebird
注意⚠️一定要科学上网,Terminal 也要处于科学上网环境。
安装 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 验证是否安装成功。
命令行登录
在 Terminal 执行:
shorebird login
我选择的是 Microsoft 方式登录,你也可以选择 Google 登录。
初始化
在 Terminal
定位到工程的根目录,执行初始化命令:
shorebird init
执行成功后,工程根目录下会自动生成 shorebird.yaml 文件,里面保存了app_id 信息,并且被pubspec.yaml 引用。
Android 目录下的 AndroidManifest.xml 文件会自动添加 INTERNET 权限。
在 Shorebird Console 控制台自动创建一个应用,关联的就是你的本地工程。
Android 端
发布版本
shorebird release android
会生成 app-release.aab 文件。如果你需要生成 APK 格式包,执行命令:
shorebird release android --artifact apk
android 打包成功后,显示当前app版本、平台类型、flutter版本信息。
输入 y 继续下一步,将版本上传到 Shorebird Console 控制台。
版本上传并发布成功后,显示版本信息,可以在 Shorebird Console 查看。
修改代码
这里简单修改下app的主题颜色和计数器的步长。
发布补丁
shorebird patch android
android 补丁生成成功后,显示当前app版本、平台cup架构信息。
输入 y 继续下一步,将补丁上传至 Shorebird Console 控制台。
补丁上传成功:
iOS端 发布版本 和 发布补丁 流程和安卓类似,但必须是注册了 Apple开发者帐户 的开发设备的测试包。构建之前,请在 Xcode 中配置好证书。
iOS发布版本:shorebird release ios
iOS发布补丁:shorebird patch ios
热更新效果图:
可以看到,app 第二次打开后,主题颜色从紫色变成了橙色,计数器的步长从 1 变成 2,热更新成功。