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 版本与shorebird 中 flutter 版本对应,虽然shorebird文档中也说明打基准包的时候可以指定 flutter 版本,shorebird release android --flutter-version 3.19.0)
登录
执行shorebird login进行登录
选择合适的登录方式即可
初始化项目
cd 到对应项目的根目录执行 shorebird init
- 会生成
shorebird.yaml文件
auto_update 默认是注释的,即默认为自动更新,如果需要手动更新则解开注释即可
- 在
pubspec.yaml文件assets中自动引入- shorebird.yaml
- 在
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
--artifact=apk输出的是apk,如果不需要apk格式则不需要加此命令--target-platform=android-arm,android-arm64由于shorebird默认打包是arm,arm64,x86架构,可以指定架构--dart-defineflutter的打包命令参数也支持
2. iOS
shorebird release ios --export-options-plist=/Users/**/ExportOptions.plist --dart-define=ENV_TYPE_NAME=app
-export-options-plist=/Users/**/ExportOptions.plistios打包导出文件,可以用xcode打一个ipa包就有这个文件了
打更新包
shorebird patch [android|ios]
同时打 Android、iOS 更新包
基准包与更新包都在shorebird服务器上
遇到问题
- 资源热更新不会生效
native代码不建议热更新