温馨提示×

如何在Debian打包Flutter

小樊
47
2026-10-09 23:50:46
栏目: 智能运维

在 Debian 上“打包 Flutter”通常有两种含义,需要先区分一下:

  1. 把 Flutter 应用打包成 Debian 包(.deb)(最常见)
  2. 把 Flutter SDK 本身打包成 Debian 包(较少见,一般用于内部分发)

下面分别说明。


一、把 Flutter 应用打包成 .deb(推荐方式)

1. 准备环境

sudo apt update
sudo apt install -y build-essential dpkg-dev clang cmake \
  ninja-build pkg-config libgtk-3-dev liblzma-dev

2. 构建 Linux 版本

flutter config --enable-linux-desktop
flutter build linux --release

构建产物在:

build/linux/x64/release/bundle/

3. 目录结构(推荐)

myapp/
├── DEBIAN/
│   └── control
├── usr/
│   ├── bin/myapp
│   ├── lib/myapp/
│   └── share/applications/myapp.desktop

4. 编写 control 文件

DEBIAN/control 示例:

Package: myapp
Version: 1.0.0
Section: utils
Priority: optional
Architecture: amd64
Depends: libgtk-3-0, libgl1, libx11-6
Maintainer: you <you@example.com>
Description: My Flutter Linux App
 A simple Flutter application packaged for Debian.

5. 复制文件

mkdir -p myapp/usr/lib/myapp
cp -r build/linux/x64/release/bundle/* myapp/usr/lib/myapp/

mkdir -p myapp/usr/bin
cat > myapp/usr/bin/myapp <<'EOF'
#!/bin/bash
exec /usr/lib/myapp/myapp "$@"
EOF
chmod +x myapp/usr/bin/myapp

6. 桌面文件(可选)

usr/share/applications/myapp.desktop

[Desktop Entry]
Name=MyApp
Exec=myapp
Type=Application
Categories=Utility;

7. 构建 .deb

dpkg-deb --build myapp

生成:

myapp.deb

二、用 dh 方式打包(更“Debian 风格”)

适合发布到仓库或 PPA:

sudo apt install dh-make
dh_make --createorig

修改 debian/rules,在 override_dh_auto_build 中调用:

flutter build linux --release

这种方式更复杂,但更符合 Debian 打包规范。


三、把 Flutter SDK 打包(不常见)

一般不推荐,因为:

  • Flutter 更新频繁
  • 官方已提供 tarball
  • Debian 官方仓库未收录

如果必须:

  • 用 dh-make 创建包
  • 安装到 /opt/flutter
  • 在 PATH 中软链

四、常见问题

运行提示找不到库

ldd build/linux/x64/release/bundle/myapp

缺什么装什么。

架构不匹配

确保:

dpkg --print-architecture

与 control 中一致。


如果你愿意,可以告诉我:

  • 是 应用 还是 SDK
  • 是否要 发布到仓库 / PPA
  • Flutter 版本

我可以给你一份可直接用的打包脚本。

0 踩