网站建设 郑州,做网站需要的公司,湖南省网站建设项目,电子简历表格手机版因为windows应用一般大家都是从网上下载的#xff0c;后期版本肯定会更新#xff0c;那用flutter开发windows应用#xff0c;怎么实现应用内版本更新功能了#xff1f;可以使用auto_updater库#xff0c; 这个插件允许 Flutter 桌面 应用自动更新自己 (基于 sparkle 和 wi…
因为windows应用一般大家都是从网上下载的后期版本肯定会更新那用flutter开发windows应用怎么实现应用内版本更新功能了可以使用auto_updater库 这个插件允许 Flutter 桌面 应用自动更新自己 (基于 sparkle 和 winsparkle) 地址如下
pub仓库地址auto_updater | Flutter Package github仓库地址https://github.com/leanflutter/auto_updater 中文文档地址https://github.com/leanflutter/auto_updater/blob/main/README-ZH.md
开始使用
先添加依赖将此添加到你的软件包的 pubspec.yaml 文件
dependencies:auto_updater: ^0.1.7
windows使用需要安装openssl
安装教程windows安装Chocolatey方法注意事项以及安装openssl方法-CSDN博客
然后在main.dart中添加下面代码
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());
}
生成私钥
运行以下命令需要分别在 macOS 和 Windows 系统中运行该命令。
dart run auto_updater:generate_keys 命令将为你生成私钥dsa_priv.pem及公钥dsa_pub.pem请备份你的私钥并确保其安全并将公钥作为 Windows 资源添加到项目中。 macOS运行命令后输出
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:keySUPublicEDKey/keystringpfIShU4dEXqPd5ObYNfDBiQWcXozk7estwzTnF9BamQ/string
更改文件 macos/Runner/Info.plist 如下
?xml version1.0 encodingUTF-8?
!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd
plist version1.0
dict... keySUPublicEDKey/keystringbHaXClrRGMmKoKP/3HJnr/jn2ODTRPAM3VZhhkI9ZvY/string
/dict
/plist
Windows运行命令后输出
Generated two files:
dsa_priv.pem: your private key. Keep it secret and dont 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!
更改文件 windows/runner/Runner.rc 如下 .../
//
// WinSparkle
//// And verify signature using DSA public key:
DSAPub DSAPEM ../../dsa_pub.pem
打包应用 为了简化打包的过程这里使用了 Flutter Distributor 一个专门用于打包和发布 Flutter 应用的完整工具。官方网站Getting Started | Flutter Distributor 安装flutter_distributor
#安装命令
dart pub global activate flutter_distributor安装Inno setup
必须安装Inno Setup 6 并且添加中文语言包且安装目录要使用默认的C盘里面否则打包失败。因为Flutter Distributor打包exe是基于inno setup 6实现的默认官网是英文版本的打包exe之后点击安装都是英文所以我找到了中文版的inno setup 6和中文语言包下载地址如下
Inno Setup 6和中文安装包下载地址inno setup 带中文包.zip - 蓝奏云 添加distribute_options.yaml添加到你的项目根目录
output: dist/
releases:- name: devjobs:- name: release-windowspackage:platform: windowstarget: exebuild_args:dart-define:APP_ENV: dev添加 make_config.yaml 到你的项目 windows/packaging/exe 需要手动创建目录 make_config.yaml内容 安装目录和快捷方式的名字发布者名称配置等
# AppId 的值唯一标识此应用。
# 不要在其他应用的安装程序中使用相同的 AppId 值。
# 以下为示例代码实际根据你的项目进行替换
app_id: 5B566538-42B1-4826-A479-AF079F24A65D
publisher: Jory Cai
display_name: Hello Hado
create_desktop_icon: true
install_dir_name: hado_world
locales:- en- zh开始生成exe文件
flutter_distributor package --platform windows --targets exe
编译成功后 对生成的exe文件进行升级签名后面的路径要是你自己生成的文件路径 dart run auto_updater:sign_update dist/1.1.1/flutter_windows-1.1.11.1.1-windows-setup.exe
签名后的输入要添加到appcast.xml后面的dsaSignature属性里面 appcast.xml内容配置更新版本和更新说明还有更新文件下载链接等内容
?xml version1.0 encodingUTF-8?
rss version2.0 xmlns:sparklehttp://www.andymatuschak.org/xml-namespaces/sparklechanneltitleauto_updater_example/titledescriptionMost recent updates to auto_updater_example/descriptionlanguageen/languageitemtitleVersion 1.1.0/title#发行说明-读取html方式(2选1)sparkle:releaseNotesLinkhttps://your_domain/your_path/release_notes.html/sparkle:releaseNotesLink#发行说明-写死方式(2选1)description![CDATA[ulli1、新增XX功能/lili2、新增XX功能/li/ul]]/descriptionpubDateSun, 16 Feb 2022 12:00:00 0800/pubDate#你更新程序的地址enclosure urlhttp://wwww.xxx.com/1.1.02/auto_updater_example-1.1.02-macos.zipsparkle:edSignaturepbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAAsparkle:version1.1.0sparkle:osmacoslength13400992typeapplication/octet-stream //itemitemtitleVersion 1.1.0/title#发行说明-读取html方式(2选1)sparkle:releaseNotesLinkhttps://your_domain/your_path/release_notes.html/sparkle:releaseNotesLink#发行说明-写死方式(2选1)description![CDATA[ulli1、新增XX功能/lili2、新增XX功能/li/ul]]/descriptionpubDateSun, 16 Feb 2022 12:00:00 0800/pubDate#你更新程序的地址enclosure urlhttp://www.xx.com/1.1.02/auto_updater_example-1.1.02-windows.exesparkle:dsaSignatureMEUCIQCVbVzVID7H3aUzAY5znpiySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rksparkle:version1.1.02sparkle:oswindowslength0typeapplication/octet-stream //item/channel
/rss新版本更新操作
如果你的程序后续更新了版本升级了就修改项目根目录里面的 pubspec.yaml文件版本 修改完之后再执行命令重新打包
flutter_distributor package --platform windows --targets exe
打包后就会在项目根目录dist下面出现响应版本的exe 然后运行命令对这个exe进行签名
dart run auto_updater:sign_update dist/1.1.0/flutter_windows-1.1.01.1.0-windows-setup.exe
将签名后的结果添加到appcast.xml里面 并且修改appcast.xml里面响应的版本和更新说明 然后启动历史版本的程序检查更新 点击安装更新后 等待下载完成点击安装更新 就会杀死现在的进程然后重新执行安装操作