flutter 版本自动更新调研

2024-07-19 1563阅读

一, auto_updater 

SDK:FLUTTER

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

    需要分别在 macOS 和 Windows 系统中运行该命令。

    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: SUPublicEDKey pfIShU4dEXqPd5ObYNfDBiQWcXozk7estwzTnF9BamQ=

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

    ... + SUPublicEDKey

    + bHaXClrRGMmKoKP/3HJnr/jn2ODTRPAM3VZhhkI9ZvY=

    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/ 目录。

    auto_updater_example Most recent updates to auto_updater_example en Version 1.1.0 https://your_domain/your_path/release_notes.html Sun, 16 Feb 2022 12:00:00 +0800 Version 1.1.0 https://your_domain/your_path/release_notes.html Sun, 16 Feb 2022 12:00:00 +0800

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

    启动测试更新服务器:

     
    

    cd dist/ serve -l 5002

    故障排除

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

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

       
      

      com.apple.security.network.client com.apple.security.network.server com.apple.security.app-sandbox

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

VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]