确保Flutter项目已启用Linux平台支持,在pubspec.yaml文件中添加linux到desktop字段,并配置基础元数据:
flutter:
uses-material-design: true
assets: # 可选:添加应用所需资源
- images/
desktop:
- linux # 启用Linux平台
运行flutter pub get同步依赖。
flutter_launcher_icons(可选,用于生成应用图标):flutter pub add flutter_launcher_icons
flutter pub run flutter_launcher_icons:main
flutter_build_debian(必需,用于打包为.deb):flutter pub add flutter_build_debian
运行以下命令编译Flutter项目为Linux原生可执行文件:
flutter build linux
构建完成后,输出文件位于build/linux/x64/release/bundle/目录(包含linux/子目录,内有原生二进制文件)。
在项目根目录创建debian.yaml文件,定义.deb包的关键信息(如包名、版本、依赖等)。示例如下:
flutter_app:
command: your_app_name # 替换为你的应用可执行文件名(如"mega_cool_app")
arch: amd64 # 架构(通常为amd64,对应x64)
parent: /usr/local/lib/your_app_name # 应用安装父目录
nonInteractive: false # 是否允许静默安装(false表示需要用户确认)
control:
Package: your-app-name # Debian包名(小写,无空格)
Version: 1.0.0 # 应用版本
Architecture: amd64 # 架构(与flutter_app.arch一致)
Priority: optional # 包优先级(optional/extra/recommended等)
Depends: # 依赖项(如flutter运行时)
- flutter
Maintainer: Your Name <your.email@example.com> # 维护者信息
Description: A brief description of your Flutter app. # 应用描述
注意:command需与flutter build linux生成的二进制文件名一致(默认为项目名)。
运行以下命令构建.deb文件:
flutter pub run flutter_build_debian
构建完成后,.deb文件将生成在build/debian/目录下(文件名格式为{package-name}_{version}_{arch}.deb,如your-app-name_1.0.0_amd64.deb)。
将生成的.deb文件分发给用户,用户可通过以下命令安装:
sudo dpkg -i your-app-name_1.0.0_amd64.deb
若安装过程中提示依赖缺失,APT会自动提示并安装所需依赖(如flutter)。
flutter_build_debian提示缺少依赖,需手动安装(如sudo apt install flutter)。flutter_launcher_icons生成的图标会自动适配Linux桌面环境(如GNOME、KDE)。arch字段与目标设备架构一致(如arm64用于ARM设备)。