flutter 版本自动更新调研

一, auto_updater

SDK FLUTTER

PLATFORM: MACOS WINDOWS

This plugin allows Flutter desktop apps to automatically update themselves (based on sparkle and winsparkle).

许可证 : MIT

Sparkle

Sparkle的原理是根据提前配置好的xml文件地址,每次启动后解析xml,看看有没有比当前版本新的数据,有的话提示更新。 xml文件可以存在任何可以访问xml元数据的服务器,包括 GitHub 仓库。

详细接入教程macOS 使用 Sparkle 检查软件自更新

CocoaPods的安装与使用_cocoapods安装_ailinghao的博客-CSDN博客

winsparkle

是一个Windows的App更新框架,它是一个Windows下应用程序的即插即忘的软件升级库。

该库容易使用以及发布,WinSparkle.dll没有任何额外的依赖(甚至没有动态CRT)。只需要包含该文件即可,并且它的API都是C语言形式的,可以用任何语言来使用它。

工具包以及语言依赖:WinSparkle的UI使用本地Windows控制器的且它是在单独的线程中运行的,因此不用担心和自己所选择的GUI工具(wxWidgets,QT,WinForms,WPF等)产生兼容性问题。

win_sparkle_set_appcast_url:为应用程序设置URL,只支持http以及https格式。关于URL地址可参考此链接获取更多信息。

实例:win_sparkle_set_appcast_url("https://raw.githubusercontent.com/LibreVR/Revive/master/appcast.xml")

win_sparkle_set_can_shutdown_callback:设置回调函数用来查询应用程序是否可以结束。在尝试启动安装程序前,该回调会被调用以询问host是否准备好关闭。若host应用程序能够安全结束,则该回调返回TRUE;反之为FALSE。

详细接入教程

auto_updater 快速开始

集成 sdk

将此添加到你的软件包的 pubspec.yaml 文件:

dependencies: auto_updater: ^0.1.7

dependencies: auto_updater: git: url: https://github.com/leanflutter/auto_updater.gitref: main

⚠️ Windows requirements
  • openssl

运行以下命令:

使用 Chocolatey

复制代码

choco install openssl

用法

import 'package:auto_updater/auto_updater.dart'; void main() async {

// 必须加上这一行。

WidgetsFlutterBinding.ensureInitialized(); String feedURL = 'http://localhost:5002/appcast.xml'; await autoUpdater.setFeedURL(feedURL); await autoUpdater.checkForUpdates(); await autoUpdater.setScheduledCheckInterval(3600); runApp(MyApp()); }

请看这个插件的示例应用,以了解完整的例子。

发布你的应用

生成私钥

运行以下命令:

dart run auto_updater:generate_keys

需要分别在 macOSWindows 系统中运行该命令。

macOS

准备使用 EdDSA 签名算法进行签名:

输出:

复制代码

A key has been generated and saved in your keychain. Add the `SUPublicEDKey` key to the Info.plist of each app for which you intend to use Sparkle for distributing updates. It should appear like this: <key>SUPublicEDKey</key> <string>pfIShU4dEXqPd5ObYNfDBiQWcXozk7estwzTnF9BamQ=</string>

更改文件 macos/Runner/Info.plist 如下:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> ... + <key>SUPublicEDKey</key>

+ <string>bHaXClrRGMmKoKP/3HJnr/jn2ODTRPAM3VZhhkI9ZvY=</string> </dict> </plist>

Windows

准备使用 DSA 签名算法进行签名:

输出:

复制代码

Generated two files: dsa_priv.pem: your private key. Keep it secret and don't share it! dsa_pub.pem: public counterpart to include in youe app. BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE! If you lose it, your users will be unable to upgrade!

命令将为你生成私钥(dsa_priv.pem)及公钥(dsa_pub.pem),请备份你的私钥并确保其安全,并将公钥作为 Windows 资源添加到项目中。

更改文件 windows/runner/Runner.rc 如下:

... +/

+//

+// WinSparkle

+//

+// And verify signature using DSA public key:

+DSAPub DSAPEM "../../dsa_pub.pem"

打包应用

为了简化打包的过程,这里使用了 Flutter Distributor ,一个专门用于打包和发布 Flutter 应用的完整工具。

distribute_options.yaml 添加到你的项目根目录。

output: dist/releases: - name: devjobs: - name: release-macospackage: platform: macostarget: zipbuild_args: dart-define: APP_ENV: dev

查看完整文档:https://distributor.leanflutter.org/configuration/makers/exe - name: release-windowspackage: platform: windowstarget: exebuild_args: dart-define: APP_ENV: dev

macOS

运行以下命令:

复制代码

flutter_distributor release --name dev --jobs release-macos

Windows

运行以下命令:

复制代码

flutter_distributor release --name dev --jobs release-windows

获取签名
macOS

运行以下命令:

复制代码

dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-macos.zip

输出:

复制代码

sparkle:edSignature="pbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAA==" length="13400992"

将获得的新签名更新到 appcast.xml 文件 enclosure 节点的 sparkle:edSignature 属性值。

Windows

运行以下命令:

复制代码

dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-windows-setup.exe

输出:

复制代码

sparkle:dsaSignature="MEUCIQCVbVzVID7H3aUzAY5znpi+ySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rk=" length="13400992"

将获得的新签名更新到 appcast.xml 文件 enclosure 节点的 sparkle:dsaSignature 属性值。

分发应用

appcast.xml 添加到你的项目 dist/ 目录。

<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"> <channel> <title>auto_updater_example</title> <description>Most recent updates to auto_updater_example</description> <language>en</language> <item> <title>Version 1.1.0</title> <sparkle:releaseNotesLink> https://your_domain/your_path/release_notes.html </sparkle:releaseNotesLink> <pubDate>Sun, 16 Feb 2022 12:00:00 +0800</pubDate> <enclosure url="1.1.0+2/auto_updater_example-1.1.0+2-macos.zip"sparkle:edSignature="pbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAA=="sparkle:version="1.1.0"sparkle:os="macos"length="13400992"type="application/octet-stream" /> </item> <item> <title>Version 1.1.0</title> <sparkle:releaseNotesLink> https://your_domain/your_path/release_notes.html </sparkle:releaseNotesLink> <pubDate>Sun, 16 Feb 2022 12:00:00 +0800</pubDate> <enclosure url="1.1.0+2/auto_updater_example-1.1.0+2-windows.exe"sparkle:dsaSignature="MEUCIQCVbVzVID7H3aUzAY5znpi+ySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rk="sparkle:version="1.1.0+2"sparkle:os="windows"length="0"type="application/octet-stream" /> </item> </channel> </rss>

本示例中 macOSWindows 使用同一个 appcast.xml 文件,你需根据配置 sparkle:os 属性的值。

启动测试更新服务器:

复制代码

cd dist/ serve -l 5002

故障排除

macOS
  • 确保按照 Sparkle 文档中的说明添加了 sparkle pod

  • 通过将以下内容添加到您的授权文件以进行调试和发布,确保您已添加并启用应用程序的网络功能并禁用沙箱以进行发布

复制代码

<key>com.apple.security.network.client</key> <true/> <key>com.apple.security.network.server</key> <true/> <key>com.apple.security.app-sandbox</key> <false/>

API

AutoUpdater

Methods

setFeedURL

设置 url 并初始化 auto updater.

checkForUpdates

检查更新,在此之前必须先调用 setFeedURL.

setScheduledCheckInterval

设置检查时间间隔,默认 86400,最少 3600, 设置为0 代表不更新

二, flutter_autoupdate 1.0.0

This library allows you to easily add auto-update functionality to your Android, iOS, and Windows Flutter application.

SDK: FLUTTER

PLATFORM: ANDROID. IOS Windows

许可证 : BSD-3-Clause license

三, flutter_xupdate

cloud.tencent.com

PLATFORM: ANDROID. IOS

A Flutter plugin for XUpdate -- Android Update Library。See the use Chinese Document for details。

flutter_xupdate 让你一键实现flutter应用版本更新

Flutter XUpdate 是否支持苹果iOS版本更新

相关推荐
AiFlutter9 小时前
Flutter之Package教程
flutter
Mingyueyixi13 小时前
Flutter Spacer引发的The ParentDataWidget Expanded(flex: 1) 惨案
前端·flutter
crasowas1 天前
Flutter问题记录 - 适配Xcode 16和iOS 18
flutter·ios·xcode
老田低代码2 天前
Dart自从引入null check后写Flutter App总有一种难受的感觉
前端·flutter
AiFlutter2 天前
Flutter Web首次加载时添加动画
前端·flutter
ZemanZhang4 天前
Flutter启动无法运行热重载
flutter
AiFlutter4 天前
Flutter-底部选择弹窗(showModalBottomSheet)
flutter
帅次4 天前
Android Studio:驱动高效开发的全方位智能平台
android·ide·flutter·kotlin·gradle·android studio·android jetpack
程序者王大川4 天前
【前端】Flutter vs uni-app:性能对比分析
前端·flutter·uni-app·安卓·全栈·性能分析·原生
yang2952423614 天前
使用 Vue.js 将数据对象的值放入另一个数据对象中
前端·vue.js·flutter