跳到内容
Tauri

Flathub

有关 Flatpak 工作原理的详细信息,请阅读 构建你的第一个 Flatpak

本指南假定你希望通过 Flathub(Flatpak 最常用的分发平台)分发你的 Flatpak。如果你计划使用其他平台,请查阅其文档。

为了在 Flatpak 运行时中测试你的应用程序,你可以先在本地构建 Flatpak,然后再将你的应用程序上传到 Flathub。如果你想快速分享开发版本,这也会很有帮助。

1. 安装 flatpakflatpak-builder

要在本地构建 Flatpak,你需要 flatpakflatpak-builder 工具。例如,在 Ubuntu 上你可以运行此命令

终端窗口
sudo apt install flatpak flatpak-builder

2. 安装 Flatpak 运行时

终端窗口
flatpak install flathub org.gnome.Platform//46 org.gnome.Sdk//46

3. 构建 Tauri 应用程序的 .deb 文件

4. 创建一个 AppStream MetaInfo 文件

5. 创建 flatpak 清单

flatpak-builder.yaml
id: <identifier>
runtime: org.gnome.Platform
runtime-version: '46'
sdk: org.gnome.Sdk
command: <main_binary_name>
finish-args:
- --socket=wayland # Permission needed to show the window
- --socket=fallback-x11 # Permission needed to show the window
- --device=dri # OpenGL, not necessary for all projects
- --share=ipc
- --talk-name=org.kde.StatusNotifierWatcher # Optional: needed only if your app uses the tray icon
- --filesystem=xdg-run/tray-icon:create # Optional: needed only if your app uses the tray icon - see an alternative way below
# - --env=WEBKIT_DISABLE_COMPOSITING_MODE=1 # Optional: may solve some issues with black webviews on Wayland
modules:
- name: binary
buildsystem: simple
sources:
# A reference to the previously generated flatpak metainfo file
- type: file
path: flatpak.metainfo.xml
# If you use GitHub releases, you can target an existing remote file
- type: file
url: https://github.com/your_username/your_repository/releases/download/v1.0.1/yourapp_1.0.1_amd64.deb
sha256: 08305b5521e2cf0622e084f2b8f7f31f8a989fc7f407a7050fa3649facd61469 # This is required if you are using a remote source
only-arches: [x86_64] # This source is only used on x86_64 Computers
# You can also use a local file for testing
# - type: file
# path: yourapp_1.0.1_amd64.deb
build-commands:
- set -e
# Extract the deb package
- mkdir deb-extract
- ar -x *.deb --output deb-extract
- tar -C deb-extract -xf deb-extract/data.tar.gz
# Copy binary
- 'install -Dm755 deb-extract/usr/bin/<executable_name> /app/bin/<executable_name>'
# If you bundle files with additional resources, you should copy them:
- mkdir -p /app/lib/<product_name>
- cp -r deb-extract/usr/lib/<product_name>/. /app/lib/<product_name>
- find /app/lib/<product_name> -type f -exec chmod 644 {} \;
# Copy desktop file + ensure the right icon is set
- sed -i 's/^Icon=.*/Icon=<identifier>/' deb-extract/usr/share/applications/<product_name>.desktop
- install -Dm644 deb-extract/usr/share/applications/<product_name>.desktop /app/share/applications/<identifier>.desktop
# Copy icons
- install -Dm644 deb-extract/usr/share/icons/hicolor/128x128/apps/<main_binary_name>.png /app/share/icons/hicolor/128x128/apps/<identifier>.png
- install -Dm644 deb-extract/usr/share/icons/hicolor/32x32/apps/<main_binary_name>.png /app/share/icons/hicolor/32x32/apps/<identifier>.png
- install -Dm644 deb-extract/usr/share/icons/hicolor/256x256@2/apps/<main_binary_name>.png /app/share/icons/hicolor/256x256@2/apps/<identifier>.png
- install -Dm644 flatpak.metainfo.xml /app/share/metainfo/<identifier>.metainfo.xml

Gnome 46 运行时包含标准 Tauri 应用程序的所有依赖项及其正确的版本。

5. 安装并测试应用程序

终端窗口
# Install the flatpak
flatpak-builder --force-clean --user --disable-cache --repo flatpak-repo flatpak flatpak-builder.yaml
# Run it
flatpak run <your flatpak id> # or via your desktop environment
# Update it
flatpak -y --user update <your flatpak id>

如果你的最终二进制文件需要的库比默认的 Tauri 应用程序多,你需要在 Flatpak 清单中添加它们。有两种方法可以做到这一点。对于快速本地开发,简单地包含本地系统中已构建的库文件 (.so) 可能会有效。但是,不建议将此用于 Flatpak 的最终构建,因为你的本地库文件不是为 Flatpak 运行时环境构建的。这可能会引入各种难以发现的错误。因此,建议在 Flatpak 中作为构建步骤从源代码构建你的程序所依赖的库。

1. Fork Flathub 仓库

2. 克隆 Fork

终端窗口
git clone --branch=new-pr git@github.com:your_github_username/flathub.git

3. 进入仓库

终端窗口
cd flathub

4. 创建新分支

终端窗口
git checkout -b your_app_name

5. 将你的应用程序清单添加到分支。提交你的更改,然后推送它们。

6. 在 GitHub 上针对 new-pr 分支打开一个拉取请求

7. 你的应用程序现在将进入审查过程,在此过程中你可能会被要求对你的项目进行更改。

当你的拉取请求获得批准后,你将收到编辑应用程序仓库的邀请。从那时起,你可以持续更新你的应用程序。

你可以在 Flatpak 文档中阅读更多相关内容


© 2025 Tauri 贡献者。CC-BY / MIT