应用图标
Tauri 默认提供一套基于其 Logo 的图标集。这不是您发布应用程序时想要的。为了解决这个常见问题,Tauri 提供了 icon 命令,该命令将接受一个输入文件(默认为 "./app-icon.png"),并为各种平台创建所有必需的图标。
npm run tauri iconyarn tauri iconpnpm tauri icondeno task tauri iconcargo tauri icon> pnpm tauri icon --help
Generate various icons for all major platforms
Usage: pnpm run tauri icon [OPTIONS] [INPUT]
Arguments: [INPUT] Path to the source icon (squared PNG or SVG file with transparency) [default: ./app-icon.png]
Options: -o, --output <OUTPUT> Output directory. Default: 'icons' directory next to the tauri.conf.json file -v, --verbose... Enables verbose logging -p, --png <PNG> Custom PNG icon sizes to generate. When set, the default icons are not generated --ios-color <IOS_COLOR> The background color of the iOS icon - string as defined in the W3C's CSS Color Module Level 4 <https://www.w3.org/TR/css-color-4/> [default: #fff] -h, --help Print help -V, --version Print version桌面图标将默认放置在您的 src-tauri/icons 文件夹中,它们将自动包含在您的构建应用中。如果您想从不同的位置获取图标,可以编辑 tauri.conf.json 文件的这一部分
{ "bundle": { "icon": [ "icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico" ] }}移动图标将直接放置在 Xcode 和 Android Studio 项目中!
如果您更喜欢自己构建这些图标,例如,如果您希望为小尺寸设计一个更简单的设计,或者因为您不想依赖 CLI 的内部图像大小调整,则必须确保您的图标满足某些要求
icon.icns:icns文件所需的图层大小和名称在 Tauri 仓库中进行了描述icon.ico:ico文件必须包含 16、24、32、48、64 和 256 像素的图层。为了在**开发**中获得最佳的 ICO 图像显示效果,32 像素的图层应该是第一个图层。png:png 图标的要求是:宽度 == 高度,RGBA(RGB + 透明度),以及每像素 32 位(每通道 8 位)。桌面常用的尺寸是 32、128、256 和 512 像素。我们建议至少与tauri icon的输出匹配:32x32.png、128x128.png、128x128@2x.png和icon.png。
在 Android 上,您需要具有相同要求但尺寸不同的 png 图标。它们还需要直接放置在 Android Studio 项目中
src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png和ic_launcher_round.png:49x49pxic_launcher_foreground.png:162x162px
mipmap-mdpi/ic_launcher.png和ic_launcher_round.png:48x48pxic_launcher_foreground.png:108x108px
mipmap-xhdpi/ic_launcher.png和ic_launcher_round.png:96x96pxic_launcher_foreground.png:216x216px
mipmap-xxhdpi/ic_launcher.png和ic_launcher_round.png:144x144pxic_launcher_foreground.png:324x324px
mipmap-xxxhdpi/ic_launcher.png和ic_launcher_round.png:192x192pxic_launcher_foreground.png:432x432px
如果无法使用 tauri icon,我们建议改用 Android Studio 的图像资源工作室。
在 iOS 上,您需要具有相同要求但**没有透明度**且尺寸不同的 png 图标。它们还需要直接放置在 Xcode 项目的 src-tauri/gen/apple/Assets.xcassets/AppIcon.appiconset/ 中。预期需要以下图标
- 20px,1 倍、2 倍、3 倍,外加一个额外图标
- 29px,1 倍、2 倍、3 倍,外加一个额外图标
- 40px,1 倍、2 倍、3 倍,外加一个额外图标
- 60px,2 倍、3 倍
- 76px,1 倍、2 倍
- 83.5px,2 倍
- 512px,2 倍,保存为
AppIcon-512@2x.png
文件名为 AppIcon-{size}x{size}@{scaling}{extra}.png 格式。对于 20px 图标,这意味着您需要 20x20、40x40 和 60x60 尺寸的图标,名称分别为 AppIcon-20x20@1x.png、AppIcon-20x20@2x.png、AppIcon-20x20@3x.png,以及另外保存一个 2x 的图标,命名为 AppIcon-20x20@2x-1.png (“额外图标”)。
© 2025 Tauri 贡献者。CC-BY / MIT