Flutter Shorebird 接入流程记录

197 阅读2分钟

Shorebird 集成步骤(以 Mac 为例)

安装

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

查看是否安装成功

执行shorebird doctor

Shorebird 1.6.76 • git@github.com:shorebirdtech/shorebird.git
Flutter 3.38.6 • revision 55c197eb61ef2219a709002c39ffa445b05600f8
Engine • revision 6062c68600c53ff4e1fecf3ce79157ef4ce33000

出现以上信息说明安装成功(ps: 建议本地 flutter 版本与shorebirdflutter 版本对应,虽然shorebird文档中也说明打基准包的时候可以指定 flutter 版本,shorebird release android --flutter-version 3.19.0

登录

执行shorebird login进行登录

image.png

选择合适的登录方式即可

初始化项目

cd 到对应项目的根目录执行 shorebird init

image.png

  1. 会生成shorebird.yaml 文件

image.png auto_update 默认是注释的,即默认为自动更新,如果需要手动更新则解开注释即可

  1. pubspec.yaml文件 assets 中自动引入 - shorebird.yaml

image.png

  1. pubspec.yaml文件添加shorebird_code_push: ^2.0.5
在 main.dart 添加以下代码

import 'package:shorebird_code_push/shorebird_code_push.dart';

final updater = ShorebirdUpdater();
if (updater.isAvailable) {
  updater.checkForUpdate().then((status) {
    if (status == UpdateStatus.outdated) {
      updater.update();
    }
  });
}

如果是auto_update: false 则在合适的时机调用

打基准包

1. Android

shorebird release android --artifact=apk --target-platform=android-arm,android-arm64 --dart-define=ENV_TYPE_NAME=app
  1. --artifact=apk 输出的是 apk,如果不需要 apk 格式则不需要加此命令
  2. --target-platform=android-arm,android-arm64 由于shorebird默认打包是arm,arm64,x86 架构,可以指定架构
  3. --dart-define flutter的打包命令参数也支持

2. iOS

shorebird release ios --export-options-plist=/Users/**/ExportOptions.plist --dart-define=ENV_TYPE_NAME=app
  1. -export-options-plist=/Users/**/ExportOptions.plist ios打包导出文件,可以用 xcode 打一个 ipa 包就有这个文件了

打更新包

shorebird patch [android|ios]

 同时打 Android、iOS 更新包

基准包与更新包都在shorebird服务器上

image.png

遇到问题

  1. 资源热更新不会生效
  2. native 代码不建议热更新