flutter_distributor是一个强大的工具,支持跨平台发布和高级打包选项。
安装
确保 flutter_distributor 已安装:
1 |
$ dart pub global activate flutter_distributor |
配置文件
为高级打包配置所需的文件:
-
macOS:
-
如果打包 DMG 安装包:macos/packaging/dmg/make_config.yaml
12345678910title: 应用名称contents:- x: 448y: 244type: linkpath: "/Applications"- x: 192y: 244type: filepath: 应用名称.app -
如果打包 PKG 安装包:macos/packaging/pkg/make_config.yaml
12install-path: /Applications#sign-identity: <your-sign-identity> -
distribute_options.yaml
1output: dist/
-
-
Windows:
-
如果打包 exe 安装包:windows/packaging/exe/inno_setup.sas
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273[Setup]AppId={{APP_ID}}AppVersion={{APP_VERSION}}AppName={{DISPLAY_NAME}}AppPublisher={{PUBLISHER_NAME}}AppPublisherURL={{PUBLISHER_URL}}AppSupportURL={{PUBLISHER_URL}}AppUpdatesURL={{PUBLISHER_URL}}DefaultDirName={{INSTALL_DIR_NAME}}DisableProgramGroupPage=yesOutputDir=.OutputBaseFilename={{OUTPUT_BASE_FILENAME}}Compression=lzmaSolidCompression=yesSetupIconFile={{SETUP_ICON_FILE}}WizardStyle=modernPrivilegesRequired={{PRIVILEGES_REQUIRED}}ArchitecturesAllowed=x64ArchitecturesInstallIn64BitMode=x64CloseApplications=force[Languages]{% for locale in LOCALES %}{% if locale == 'en' %}Name: "english"; MessagesFile: "compiler:Default.isl"{% endif %}{% if locale == 'hy' %}Name: "armenian"; MessagesFile: "compiler:Languages\\Armenian.isl"{% endif %}{% if locale == 'bg' %}Name: "bulgarian"; MessagesFile: "compiler:Languages\\Bulgarian.isl"{% endif %}{% if locale == 'ca' %}Name: "catalan"; MessagesFile: "compiler:Languages\\Catalan.isl"{% endif %}{% if locale == 'zh' %}Name: "chinesesimplified"; MessagesFile: "compiler:Languages\\ChineseSimplified.isl"{% endif %}{% if locale == 'co' %}Name: "corsican"; MessagesFile: "compiler:Languages\\Corsican.isl"{% endif %}{% if locale == 'cs' %}Name: "czech"; MessagesFile: "compiler:Languages\\Czech.isl"{% endif %}{% if locale == 'da' %}Name: "danish"; MessagesFile: "compiler:Languages\\Danish.isl"{% endif %}{% if locale == 'nl' %}Name: "dutch"; MessagesFile: "compiler:Languages\\Dutch.isl"{% endif %}{% if locale == 'fi' %}Name: "finnish"; MessagesFile: "compiler:Languages\\Finnish.isl"{% endif %}{% if locale == 'fr' %}Name: "french"; MessagesFile: "compiler:Languages\\French.isl"{% endif %}{% if locale == 'de' %}Name: "german"; MessagesFile: "compiler:Languages\\German.isl"{% endif %}{% if locale == 'he' %}Name: "hebrew"; MessagesFile: "compiler:Languages\\Hebrew.isl"{% endif %}{% if locale == 'is' %}Name: "icelandic"; MessagesFile: "compiler:Languages\\Icelandic.isl"{% endif %}{% if locale == 'it' %}Name: "italian"; MessagesFile: "compiler:Languages\\Italian.isl"{% endif %}{% if locale == 'ja' %}Name: "japanese"; MessagesFile: "compiler:Languages\\Japanese.isl"{% endif %}{% if locale == 'no' %}Name: "norwegian"; MessagesFile: "compiler:Languages\\Norwegian.isl"{% endif %}{% if locale == 'pl' %}Name: "polish"; MessagesFile: "compiler:Languages\\Polish.isl"{% endif %}{% if locale == 'pt' %}Name: "portuguese"; MessagesFile: "compiler:Languages\\Portuguese.isl"{% endif %}{% if locale == 'ru' %}Name: "russian"; MessagesFile: "compiler:Languages\\Russian.isl"{% endif %}{% if locale == 'sk' %}Name: "slovak"; MessagesFile: "compiler:Languages\\Slovak.isl"{% endif %}{% if locale == 'sl' %}Name: "slovenian"; MessagesFile: "compiler:Languages\\Slovenian.isl"{% endif %}{% if locale == 'es' %}Name: "spanish"; MessagesFile: "compiler:Languages\\Spanish.isl"{% endif %}{% if locale == 'tr' %}Name: "turkish"; MessagesFile: "compiler:Languages\\Turkish.isl"{% endif %}{% if locale == 'uk' %}Name: "ukrainian"; MessagesFile: "compiler:Languages\\Ukrainian.isl"{% endif %}{% endfor %}[Tasks]Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: {% if CREATE_DESKTOP_ICON != true %}unchecked{% else %}checkedonce{% endif %}Name: "launchAtStartup"; Description: "{cm:AutoStartProgram,{{DISPLAY_NAME}}}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: {% if LAUNCH_AT_STARTUP != true %}unchecked{% else %}checkedonce{% endif %}[Files]Source: "{{SOURCE_DIR}}\\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; NOTE: Don't use "Flags: ignoreversion" on any shared system files[Icons]Name: "{autoprograms}\\{{DISPLAY_NAME}}"; Filename: "{app}\\{{EXECUTABLE_NAME}}"Name: "{autodesktop}\\{{DISPLAY_NAME}}"; Filename: "{app}\\{{EXECUTABLE_NAME}}"; Tasks: desktopiconName: "{userstartup}\\{{DISPLAY_NAME}}"; Filename: "{app}\\{{EXECUTABLE_NAME}}"; WorkingDir: "{app}"; Tasks: launchAtStartup[Run]Filename: "{app}\\{{EXECUTABLE_NAME}}"; Description: "{cm:LaunchProgram,{{DISPLAY_NAME}}}"; Flags: {% if PRIVILEGES_REQUIRED == 'admin' %}runascurrentuser{% endif %} nowait postinstall skipifsilent[Code]function InitializeSetup(): Boolean;varResultCode: Integer;beginExec('taskkill', '/F /IM 应用名称.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)Result := True;end;windows/packaging/exe/make_config.yaml
1234567891011121314151617app_id: 6L913538-42B1-4596-G479-BJ779F21A65Dpublisher: 应用名称publisher_url: https://github.com/aaa/aaadisplay_name: 应用名称executable_name: 应用名称.exeoutput_base_file_name: 应用名称.execreate_desktop_icon: trueinstall_dir_name: "{autopf64}\\应用名称"setup_icon_file: ..\..\windows\runner\resources\app_icon.icolocales:- ar- en- fa- ru- pt- trscript_template: inno_setup.sas -
如果打包 msix windows/packaging/msix/make_config.yaml
12345678910111213141516display_name: 应用名称publisher_display_name: 应用名称identity_name: 应用名称.appioimsix_version: 2.5.7.0logo_path: windows\runner\resources\app_icon.icocapabilities: internetClient, internetClientServer, privateNetworkClientServerlanguages: en-us, zh-cn, zh-tw, tr-tr,fa-ir,ru-ru,pt-br,es-esprotocol_activation: 应用名称execution_alias: 应用名称certificate_path: windows\sign.pfxcertificate_password:publisher: CN=8CB43675-F44B-4AA5-9372-E8727781BDC4install_certificate: "false"enable_at_startup: "true"startup_task:parameters: --autostart
-
-
Linux:
-
linux/packaging/appimage
有两个文件 linux/packaging/appimage/AppRun
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#!/bin/bashcd "$(dirname "$0")"export LD_LIBRARY_PATH=usr/lib# Usage infoshow_help() {cat << EOFUsage: ${0##*/} ...start app or app, when no parameter is given, app is executed.-v show versionEOF}show_version() {printf "app version "jq .version <./data/flutter_assets/version.json}# Initialize variables:service=0 #declare -i serviceOPTIND=1# Resetting OPTIND is necessary if getopts was used previously in the script.# It is a good idea to make OPTIND local if you process options in a function.# if no arg is provided, execute appif [[ $# == 0 ]];thenexec ./appelse# processing argumentscase $1 inappCli)exec ./appCli ${@:3}exit 0;;h)show_helpexit 0;;v) show_versionexit 0;;*)show_help >&2exit 1;;esacfilinux/packaging/appimage/make_config.yaml
123456789101112131415161718192021222324252627282930313233343536display_name: App名称icon: ./assets/images/source/ic_launcher_border.pngkeywords:- Higeneric_name: App名称actions:- name: Startlabel: startarguments:- --start- name: Stoplabel: stoparguments:- --stopcategories:- Networkstartup_notify: trueapp_run_file: AppRun# You can specify the shared libraries that you want to bundle with your app## flutter_distributor automatically detects the shared libraries that your app# depends on, but you can also specify them manually here.## The following example shows how to bundle the libcurl library with your app.## include:# - libcurl.so.4include: [] -
linux/packaging/deb 文件 linux/packaging/deb/make_config.yaml
123456789101112131415161718192021222324252627282930313233display_name: Hiddifypackage_name: hiddifymaintainer:name: hiddifyemail: linux@hiddify.compriority: optionalsection: x11installed_size: 6604essential: falseicon: ./assets/images/source/ic_launcher_border.pngpostinstall_scripts:- echo "Installed Hiddify"postuninstall_scripts:- echo "Surprised Why?"keywords:- Hiddify- Proxy- VPN- V2ray- Nekoray- Xray- Psiphon- OpenVPNgeneric_name: Hiddifycategories:- Networkstartup_notify: true -
linux/packaging/rpm 文件 linux/packaging/rpm/make_config.yaml
123456789101112131415161718192021display_name: Appurl: https://github.com/app/app-next/license: Otherpackager: ApppackagerEmail: linux@App.compriority: optionalsection: x11installed_size: 6604essential: falseicon: ./assets/images/source/ic_launcher_border.pngkeywords:- Higeneric_name: Appgroup: Applications/Internetstartup_notify: true
-
命令示例
-
打包 macOS (DMG 和 PKG)
123$ export PATH="$PATH":"$HOME/.pub-cache/bin"$ flutter_distributor package --flutter-build-args=verbose --platform macos --targets dmg,pkg -
打包 Windows (EXE 和 MSIX)
123$ export PATH="$PATH":"$HOME/.pub-cache/bin"$ flutter_distributor package --flutter-build-args=verbose --platform windows --targets exe,msix -
打包 Linux (DEB、RPM 和 AppImage)
123$ export PATH="$PATH":"$HOME/.pub-cache/bin"$ flutter_distributor package --flutter-build-args=verbose --platform linux --targets deb,rpm,appimage