Skip to content
Tauri 中文网

先决条件

为了开始使用 Tauri 构建项目,你首先需要安装一些依赖:

¥In order to get started building your project with Tauri you’ll first need to install a few dependencies:

  1. 系统依赖

    ¥System Dependencies

  2. Rust

  3. 针对移动目标进行配置(仅在为移动设备开发时才需要)

    ¥Configure for Mobile Targets (only required if developing for mobile)

系统依赖

¥System Dependencies

按照链接开始适用于你相应操作系统的操作:

¥Follow the link to get started for your respective operating system:

Linux

Tauri 需要各种系统依赖才能在 Linux 上进行开发。这些准则可能因你的发行版而异,但我们在下面列出了一些流行的发行版以帮助你进行设置。

¥Tauri requires various system dependencies for development on Linux. These may be different depending on your distribution but we’ve included some popular distributions below to help you get setup.

Terminal window
sudo apt update
sudo apt install libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
file \
libxdo-dev \
libssl-dev \
libayatana-appindicator3-dev \
librsvg2-dev

如果你的发行版未包含在上面,则你可能需要检查 Awesome Tauri 在 GitHub 上 以查看是否已创建指南。

¥If your distribution isn’t included above then you may want to check Awesome Tauri on GitHub to see if a guide has been created.

下一步:安装 Rust

¥Next: Install Rust

macOS

Tauri 使用 Xcode 和各种 macOS 和 iOS 开发依赖。

¥Tauri uses Xcode and various macOS and iOS development dependencies.

从以下位置之一下载并安装 Xcode:

¥Download and install Xcode from one of the following places:

请务必在安装后启动 Xcode,以便完成设置。

¥Be sure to launch Xcode after installing so that it can finish setting up.

Only developing for desktop targets? 如果你只打算开发桌面应用,而不是针对 iOS,那么你可以安装 Xcode 命令行工具:

¥

Only developing for desktop targets? If you’re only planning to develop desktop apps and not targeting iOS then you can install Xcode Command Line Tools instead:

Terminal window
xcode-select --install

下一步:安装 Rust

¥Next: Install Rust

Windows

Tauri 使用 Microsoft C++ Build Tools 进行开发以及 Microsoft Edge WebView2。这些都是在 Windows 上进行开发所必需的。

¥Tauri uses the Microsoft C++ Build Tools for development as well as Microsoft Edge WebView2. These are both required for development on Windows.

按照以下步骤安装所需的依赖。

¥Follow the steps below to install the required dependencies.

Microsoft C++ 构建工具

¥Microsoft C++ Build Tools

  1. 下载 Microsoft C++ 构建工具 安装程序并打开它以开始安装。

    ¥Download the Microsoft C++ Build Tools installer and open it to begin installation.

  2. 安装期间检查 “使用 C++ 进行桌面开发” 选项。

    ¥During installation check the “Desktop development with C++” option.

Visual Studio C++ Build Tools installer screenshot

下一步:安装 WebView2

¥Next: Install WebView2.

WebView2

:::tip 提示

WebView 2 已安装在 Windows 10(从版本 1803 开始​​)和更高版本的 Windows 上。如果你正在其中一个版本上进行开发,则可以跳过此步骤并直接转到 安装 Rust

¥WebView 2 is already installed on Windows 10 (from version 1803 onward) and later versions of Windows. If you are developing on one of these versions then you can skip this step and go directly to installing Rust.

:::

Tauri 使用 Microsoft Edge WebView2 在 Windows 上渲染内容。

¥Tauri uses Microsoft Edge WebView2 to render content on Windows.

通过访问 WebView2 运行时下载部分 安装 WebView2。下载 “Evergreen Bootstrapper” 并安装它。

¥Install WebView2 by visiting the WebView2 Runtime download section. Download the “Evergreen Bootstrapper” and install it.

下一步:安装 Rust

¥Next: Install Rust

Rust

Tauri 使用 Rust 构建,开发时需要它。使用以下方法之一安装 Rust。你可以在 https://www.rust-lang.org/tools/install 上查看更多安装方法。

¥Tauri is built with Rust and requires it for development. Install Rust using one of following methods. You can view more installation methods at https://www.rust-lang.org/tools/install.

使用以下命令通过 rustup 安装:

¥Install via rustup using the following command:

Terminal window
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

请务必重新启动终端(在某些情况下重新启动系统)以使更改生效。

¥Be sure to restart your Terminal (and in some cases your system) for the changes to take affect.

下一步:如果你想要为 Android 和 iOS 构建,请选择 针对移动目标进行配置;如果你想要使用 JavaScript 框架,请选择 安装 Node。否则 创建项目

¥Next: Configure for Mobile Targets if you’d like to build for Android and iOS, or, if you’d like to use a JavaScript framework, install Node. Otherwise Create a Project.

Node.js

  1. 转到 Node.js 网站,下载长期支持 (LTS) 版本并安装。

    ¥Go to Node.js website, download the Long Term Support (LTS) version and install it.

  2. 通过运行以下命令检查 Node 是否已成功安装:

    ¥Check if Node was successfully installed by running:

Terminal window
node -v
# v20.10.0
npm -v
# 10.2.3

重新启动终端以确保它识别新安装非常重要。在某些情况下,你可能需要重新启动计算机。

¥It’s important to restart your Terminal to ensure it recognizes the new installation. In some cases, you might need to restart your computer.

虽然 npm 是 Node.js 的默认包管理器,但你也可以使用其他包管理器,如 pnpm 或 yarn。要启用这些,请在你的终端中运行 corepack enable。此步骤是可选的,仅当你喜欢使用 npm 以外的包管理器时才需要。

¥While npm is the default package manager for Node.js, you can also use others like pnpm or yarn. To enable these, run corepack enable in your Terminal. This step is optional and only needed if you prefer using a package manager other than npm.

下一步:针对移动目标进行配置创建项目

¥Next: Configure for Mobile Targets or Create a project.

针对移动目标进行配置

¥Configure for Mobile Targets

如果你希望将应用定位到 Android 或 iOS,则需要安装一些其他依赖:

¥If you’d like to target your app for Android or iOS then there are a few additional dependencies that you need to install:

Android

  1. 下载并安装 来自 Android 开发者网站的 Android Studio

    ¥Download and install Android Studio from the Android Developers website

  2. 设置 JAVA_HOME 环境变量:

    ¥Set the JAVA_HOME environment variable:

Terminal window
export JAVA_HOME=/opt/android-studio/jbr
  1. 使用 Android Studio 中的 SDK 管理器安装以下内容:

    ¥Use the SDK Manager in Android Studio to install the following:

  • Android SDK 平台

    ¥Android SDK Platform

  • Android SDK 平台工具

    ¥Android SDK Platform-Tools

  • NDK (并排)

    ¥NDK (Side by side)

  • Android SDK 构建工具

    ¥Android SDK Build-Tools

  • Android SDK 命令行工具

    ¥Android SDK Command-line Tools

在 SDK 管理器中选择 “显示包详细信息” 可以安装旧版本的软件包。仅在必要时安装旧版本,因为它们可能会引入兼容性问题或安全风险。

¥Selecting “Show Package Details” in the SDK Manager enables the installation of older package versions. Only install older versions if necessary, as they may introduce compatibility issues or security risks.

  1. 设置 ANDROID_HOMENDK_HOME 环境变量。

    ¥Set ANDROID_HOME and NDK_HOME environment variables.

Terminal window
export ANDROID_HOME="$HOME/Android/Sdk"
export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"
  1. Add the Android targets with rustup:
Terminal window
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

下一步:iOS 设置创建项目

¥Next: Setup for iOS or Create a project.

iOS

  1. 在终端中使用 rustup 添加 iOS 目标:

    ¥Add the iOS targets with rustup in Terminal:

Terminal window
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
  1. 安装 Homebrew

    ¥Install Homebrew:

Terminal window
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. 使用 Homebrew 安装 Cocoapods

    ¥Install Cocoapods using Homebrew:

Terminal window
brew install cocoapods

下一步:创建项目

¥Next: Create a project.

故障排除

¥Troubleshooting

如果你在安装过程中遇到任何问题,请务必检查 故障排除指南 或联系 Tauri Discord

¥If you run into any issues during installation be sure to check the Troubleshooting Guide or reach out on the Tauri Discord.


Tauri 中文网 - 粤ICP备13048890号