Tauri 是一个构建适用于所有主流桌面和移动平台的轻快二进制文件的框架。开发者们可以集成任何用于创建用户界面的可以被编译成 HTML、JavaScript 和 CSS 的前端框架,同时可以在必要时使用 Rust、Swift 和 Kotlin 等语言编写后端逻辑。
前置需求
首先Mac下需要安装Xcodes
brew install xcode
提示:
xcodes: A full installation of Xcode.app 13.3 is required to compile
this software. Installing just the Command Line Tools is not sufficient.
好么,强制升级啊,老版本直接就不许装了。
多亏以前安装xcode,所以不能安装也没有造成影响。
安装rustc
使用rust官网的方法直接安装:
curl https://sh.rustup.rs -sSf | sh
创建项目
cargo install create-tauri-app --locked
cargo create-tauri-app
大部分都按照默认,会在当前目录创建tauri-app目录。比如 在~/目录下,就会创建~/tauri-app 目录。
安装Tauri
执行命令:
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
显示:
Your system is missing dependencies (or they do not exist in $PATH):
╭───────────────┬───────────────────────────────────────────────────────────╮
│ Tauri CLI │ Run `cargo install tauri-cli --version '^2.0.0' --locked` │
├───────────────┼───────────────────────────────────────────────────────────┤
│ Trunk │ Run `cargo install trunk --locked` │
├───────────────┼───────────────────────────────────────────────────────────┤
│ wasm32 target │ Run `rustup target add wasm32-unknown-unknown` │
╰───────────────┴───────────────────────────────────────────────────────────╯
Make sure you have installed the prerequisites for your OS: https://tauri.app/start/prerequisites/, then run:
cd tauri-app
cargo tauri android init
cargo tauri ios init
For Desktop development, run:
cargo tauri dev
For Android development, run:
cargo tauri android dev
For iOS development, run:
cargo tauri ios dev
也就是需要安装三个软件,执行下面三句:
cargo install tauri-cli --version '^2.0.0' --locked
cargo install trunk --locked
rustup target add wasm32-unknown-unknown
启动Tauri
进入创建的项目目录,然后执行:
cargo tauri dev
启动后提示:
Warn Waiting for your frontend dev server to start on http://localhost:1420/...
很长时间后显示:
Compiling tauri-app-ui v0.1.0 (/Users/skywalk/tauri-app)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 4m 21s
2024-11-23T14:58:35.079600Z INFO downloading wasm-bindgen version="0.2.95"
再次运行cargo tauri dev
6: client error (Connect)
7: connection closed via error
2024-11-23T14:59:42.021750Z INFO 📡 serving static assets at -> /
2024-11-23T14:59:42.021858Z INFO 📡 server listening at:
2024-11-23T14:59:42.021888Z INFO 🏠 http://127.0.0.1:1420/
2024-11-23T14:59:42.021894Z INFO 🏠 http://[::1]:1420/
2024-11-23T14:59:42.025144Z INFO 🏠 http://localhost.:1420/
2024-11-23T14:59:42.041629Z INFO 📦 starting build
再次运行,这时候的报错:
2024-11-23T15:03:35.986282Z INFO 📡 serving static assets at -> /
2024-11-23T15:03:35.986470Z INFO 📡 server listening at:
2024-11-23T15:03:35.986497Z INFO 🏠 http://127.0.0.1:1420/
2024-11-23T15:03:35.986507Z INFO 🏠 http://[::1]:1420/
2024-11-23T15:03:35.988587Z INFO 🏠 http://localhost.:1420/
2024-11-23T15:03:35.989162Z ERROR error from server task error=Address already in use (os error 48)
2024-11-23T15:03:35.989264Z ERROR Address already in use (os error 48)
Error The "beforeDevCommand" terminated with a non-zero status code.
(base) laiweilideMacBook-Air:tauri-app skywalk$ 2024-11-23T15:03:48.992102Z ERROR ❌ error
error from build pipeline
Caused by:
0: HTML build pipeline failed (1 errors), showing first
1: error from asset pipeline
2: running wasm-bindgen
3: error minifying or copying JS loader file to stage dir
4: error writing JS loader file to stage dir
5: No such file or directory (os error 2)
再运行一次,就只有这一个报错了:
2024-11-23T16:29:16.690226Z ERROR error from server task error=Address already in use (os error 48)
2024-11-23T16:29:16.690602Z ERROR Address already in use (os error 48)
Error The "beforeDevCommand" terminated with a non-zero status code.
修改端口(不明白为什么原端口会卡住)
修改Trunk.toml文件,把端口设为1421
cat Trunk.toml
[build]
target = "./index.html"
[watch]
ignore = ["./src-tauri"]
[serve]
port = 1421
open = false
终于ok了,登录网址http://127.0.0.1:1421/
出现欢迎画面:Welcome to Tauri + Leptos
app也运行了,但是跟前面报错信息贴一块了。不过问题不大。
太奇怪了,截图找不到放哪里去了。。。。第二天才找到截图:
下面该做什么呢?