Skip to content
Tauri 中文网

Snapcraft

先决条件

¥Prerequisites

1.

Terminal window
sudo apt install snapd

2.

Terminal window
sudo snap install core22

3.

Terminal window
sudo snap install snapcraft --classic

配置

¥Configuration

  1. 创建一个 UbuntuOne 账户。

    ¥Create an UbuntuOne account.

  2. 转到 Snapcraft 网站并注册应用名称。

    ¥Go to the Snapcraft website and register an App name.

  3. 在你的项目根目录中创建一个 snapcraft.yaml 文件。

    ¥Create a snapcraft.yaml file in your projects root.

  4. 调整 snapcraft.yaml 文件中的名称。

    ¥Adjust the names in the snapcraft.yaml file.

name: appname
base: core22
version: '0.1.0'
summary: Your summary # 79 char long summary
description: |
Your description
grade: stable
confinement: strict
layout:
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/webkit2gtk-4.1:
bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/webkit2gtk-4.1
apps:
appname:
command: usr/bin/appname
desktop: usr/share/applications/appname.desktop
extensions: [gnome]
#plugs:
# - network
# Add whatever plugs you need here, see https://snapcraft.io/docs/snapcraft-interfaces for more info.
# The gnome extension already includes [ desktop, desktop-legacy, gsettings, opengl, wayland, x11, mount-observe, calendar-service ]
package-repositories:
- type: apt
components: [main]
suites: [noble]
key-id: 78E1918602959B9C59103100F1831DDAFC42E99D
url: http://ppa.launchpad.net/snappy-dev/snapcraft-daily/ubuntu
parts:
build-app:
plugin: dump
build-snaps:
- node/20/stable
- rustup/latest/stable
build-packages:
- libwebkit2gtk-4.1-dev
- build-essential
- curl
- wget
- file
- libxdo-dev
- libssl-dev
- libayatana-appindicator3-dev
- librsvg2-dev
- dpkg
stage-packages:
- libwebkit2gtk-4.1-0
- libayatana-appindicator3-1
source: .
override-build: |
set -eu
npm install
npm run tauri build -- --bundles deb
dpkg -x src-tauri/target/release/bundle/deb/*.deb $SNAPCRAFT_PART_INSTALL/
sed -i -e "s|Icon=appname|Icon=/usr/share/icons/hicolor/32x32/apps/appname.png|g" $SNAPCRAFT_PART_INSTALL/usr/share/applications/appname.desktop

说明

¥Explanation

  • name 变量定义你的应用的名称,需要设置为你之前注册的名称。

    ¥The name variable defines the name of your app and is required to be set to the name that you have registered earlier.

  • base 变量定义你正在使用哪个核心。

    ¥The base variable defines which core you are using.

  • version 变量定义版本,应随源存储库的每次更改而更新。

    ¥The version variable defines the version, and should be updated with each change to the source repository.

  • apps 部分允许你公开桌面和二进制文件以允许用户运行你的应用。

    ¥The apps section allows you to expose the desktop and binary files to allow the user to run your app.

  • package-repositories 部分允许你添加包存储库以帮助你满足依赖。

    ¥The package-repositories section allows you to add a package repository to help you satisfy your dependencies.

  • build-packages/build-snaps 定义你的 snap 的构建依赖。

    ¥build-packages/build-snaps defines the build dependencies for your snap.

  • stage-packages/stage-snaps 定义你的 snap 的运行时依赖。

    ¥stage-packages/stage-snaps defines the runtime dependencies for your snap.

  • override-pull 部分在提取源之前运行一系列命令。

    ¥The override-pull section runs a series of commands before the sources are pulled.

  • craftctl default 执行默认的拉取命令。

    ¥craftctl default performs the default pull commands.

  • organize 部分将你的文件移动到适当的目录,以便二进制和桌面文件可以公开给 apps 部分。

    ¥The organize section moves your files to the proper directories so that the binary and desktop file can be exposed to the apps sections.

构建

¥Building

Terminal window
sudo snapcraft

测试

¥Testing

Terminal window
snap run your-app

手动发布

¥Releasing Manually

Terminal window
snapcraft login # Login with your UbuntuOne credentials
snapcraft upload --release=stable mysnap_latest_amd64.snap

自动构建

¥Building automatically

  1. 在你的应用开发者页面上,单击 builds 选项卡。

    ¥On your apps developer page click on the builds tab.

  2. 单击 login with github

    ¥Click login with github.

  3. 输入你的存储库的详细信息。

    ¥Enter in your repository’s details.


Tauri 中文网 - 粤ICP备13048890号