flutter 版本自动更新调研

一, auto_updater 

SDKFLUTTER

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版本更新

  • 15
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值