1. 环境准备,以及打包步骤说明
- 环境自己准备,这篇文章只是说明打包步骤,是在项目能运行起来的前提下进行的。
- cd 到项目的根目录下
- fluttter pub get //更新项目依赖
- flutter build windows -t lib/main_development.dart // -t指定程序入口文件,执行完可以生成可执行文件xx.exe
- 直接运行xx.exe是可以正常打开的,应该运行环境我们打包的电脑都具备。如果要在其他电脑上也可以运行,就需要打包相关的依赖到一起发布给用户安装
- flutter window打包成安装包有很多种方式和方法,这里选择比较常用的
inno setup
软件制作,下面将具体介绍该软件制作exe安装包的步骤,其实基本都是下一步。。。
2. 使用inno setup软件制作exe安装包的步骤
1.下载并安装inno setup软件,inno setup下载路径:https://jrsoftware.org/isdl.php#stable,安装步骤一直下一步,自行解决。
2. 打开inno setup, 选择Create a new script file using the Script Wizard 然后下一步:
3. next→next填写应用信息
4. 默认选择应用程序目录,不用动,直接下一步
5. 选择应用程序入口,和依赖文件。程序入口选择上面提到的xx.ext文件,依赖通过add file添加所有依赖,add fold添加data文件夹以及其子文件夹,提示后会提示你的选择yes即可。
6. 这一边很重要,选择data,然后选择edit,修改destination subfold为data
7. next,next下一步选license文件,三个普通txt文件
8. 安装的时候是否请求用户的administration权限,默认是,可以选择yes或no,不过最好是yes,权限高点,对后续操作权限有利
9. 选择安装时候的语言,没有中文。。。暂时只能选择英文,网上有汉化方法
10. 添加安装包输出的目录和啊安装包名称、安装包图标。最后一个密码不用设置
11. 最后next,next,finish即可生成并保存一个iss配置文件
12. 每次运行这个iss配置文件即可生成一个可安装运行的exe文件
iss文件大致内容如下:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!#define MyAppName "xx"
#define MyAppVersion "1.0.1+1"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "xx.exe"[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{ADA3DD7E-53F6-45C5-B370-CC2C04BF892B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=D:\OpenSSL_Win64_3.1.1\install_licence.txt
InfoBeforeFile=D:\OpenSSL_Win64_3.1.1\install_before.txt
InfoAfterFile=D:\OpenSSL_Win64_3.1.1\install_after.txt
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=commandline
OutputDir=D:\OpenSSL_Win64_3.1.1
OutputBaseFilename=xx-setup
SetupIconFile=D:\OpenSSL_Win64_3.1.1\app_icon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked[Files]
Source: "D:\work\xx-pc\build\windows\runner\Release\xx.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\work\xx-pc\build\windows\runner\Release\flutter_windows.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\work\xx-pc\build\windows\runner\Release\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent[UninstallDelete]
Type: files; Name: "{autodocs}\App.gs"
Type: files; Name: "{autodocs}\App.bak"