当前位置: 首页 > news >正文

用Tauri框架构建跨平台桌面应用:1、Tauri快速开始

Tauri 是一个构建适用于所有主流桌面和移动平台的轻快二进制文件的框架。开发者们可以集成任何用于创建用户界面的可以被编译成 HTML、JavaScript 和 CSS 的前端框架,同时可以在必要时使用 Rust、Swift 和 Kotlin 等语言编写后端逻辑。

Tauri 是什么? | Tauri

首先安装依赖包

安装Ubuntu apt包

sudo apt install libwebkit2gtk-4.0-dev \build-essential \curl \wget \file \libxdo-dev \libssl-dev \libgtk-3-dev \libayatana-appindicator3-dev \librsvg2-dev

安装rustc

apt安装的版本低,需要使用官网的安装:

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

但是这个会卡住。。。

中间尝试过用apt安装好并更新到1.80版本:

apt upgrade rustc-1.80

看着说更新了,但是还是报错说rustc版本低。。。。后来是用的官网的方法:

官网方法

直接执行安装命令:

curl https://sh.rustup.rs -sSf | sh

 安装完成后提示:

Rust is installed now. Great!To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish

重新登录用户,或者执行命令激活环境:

. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh

 使用bash创建项目

sh <(curl https://create.tauri.app/sh)% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:100 16121  100 16121    0     0   7933      0  0:00:02  0:00:02 --:--:--  7937
info: downloading create-tauri-app
✔ Project name · tauri-app
✔ Identifier · com.tauri-app.app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, deno, bun)
✔ Choose your package manager · pnpm
✔ Choose your UI template · Vue - (https://vuejs.org/)
✔ Choose your UI flavor · TypeScriptTemplate created!Your system is missing dependencies (or they do not exist in $PATH):
╭────────────────────┬─────────────────────────────────────────────────────╮
│ Node.js            │ Visit https://nodejs.org/                           │
├────────────────────┼─────────────────────────────────────────────────────┤
│ webkit2gtk & rsvg2 │ Visit https://tauri.app/guides/prerequisites/#linux │
╰────────────────────┴─────────────────────────────────────────────────────╯Make sure you have installed the prerequisites for your OS: https://tauri.app/start/prerequisites/, then run:cd tauri-apppnpm installpnpm tauri android initFor Desktop development, run:pnpm tauri devFor Android development, run:pnpm tauri android dev

进入目录使用 Tauri CLI 启动开发服务器:

cd tauri-app
cargo tauri dev

这里没有运行成功,改用手动 

先安装

cargo search cargo-tauri

都不行,换一个方法:重新用cargo创建目录

使用cargo创建项目

执行命令:

cargo install create-tauri-app --locked
cargo create-tauri-app

 安装过程中会让选择模版,五种ui模版,最佳应该选哪个? Vanilla Yew Leptos Sycamore Dioxus

听AI的劝,再加上自己的主观判断,最后选了Leptos

装完之后提示:

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`            │
├───────────────┼───────────────────────────────────────────────────────────┤
│ webkit2gtk    │ Visit https://tauri.app/guides/prerequisites/#linux       │
╰───────────────┴───────────────────────────────────────────────────────────╯Make sure you have installed the prerequisites for your OS: https://tauri.app/start/prerequisites/, then run:cd tauri-appcargo tauri android initFor Desktop development, run:cargo tauri devFor Android development, run:cargo tauri android dev

后来才知道,需要按照提示安装缺失的软件,比如Tauri CLI等。 

开始 :使用 Tauri CLI 启动开发服务器:

项目创建好后,提示执行下面命令安装Tauri CLI:

cargo install tauri-cli --version "^2.0.0" --locked

安装完成提示:

  Installing /root/.cargo/bin/cargo-tauriInstalled package `tauri-cli v2.1.0` (executable `cargo-tauri`)
bash: Run: command not found

因为是远程无窗口服务器,所以最后有个bash命令没执行,理论上应该是:

您将会看到一个新的窗口被打开,该窗口正在运行您的应用。

恭喜您! 您已经创建了您自己的 Tauri 应用!🚀

后来在Mac下安装成功,看到了Tauri的窗体。

调试

报错error: crates-io is replaced with non-remote-registry source registry `mirror`

cargo search cargo-tauri

error: crates-io is replaced with non-remote-registry source registry `mirror`;

include `--registry crates-io` to use crates.io

加上这句:

[source.crates-io]
registry = "https://github.com/rust - lang/crates.io - index"
replace-with = 'mirror'

好像不管用。

用这条命令:

cargo search tauri --registry crates-io

能看到东西,但是装起来还是不错,应该还是版本问题。 

报错cannot install package `tauri 2.1.1`, it requires rustc 1.77.2 or newer

cargo install tauri

    Updating `mirror` index

error: cannot install package `tauri 2.1.1`, it requires rustc 1.77.2 or newer, while the currently active rustc version is 1.75.0

`tauri 2.0.0-rc.17` supports rustc 1.71

用apt等升级rustc,一直没升上去,最后使用官网的方法安装新版本:

curl https://sh.rustup.rs -sSf | sh

参考 初识Cargo-Rust的包管理器_cargo,rust包管理器-CSDN博客

FreeBSD系统不支持cargo install tauri-cli 

命令安装:

cargo install tauri-cli --version '^2.0.0' --locked
 

   Compiling magic_string v0.3.4
error: Host platform not yet supported by cargo-mobile2! We'd love if you made a PR to add support for this platform ❤️--> /home/skywalk/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/cargo-mobile2-0.17.4/src/os/mod.rs:22:1|
22 | compile_error!("Host platform not yet supported by cargo-mobile2! We'd love if you made a PR to add support for this platform ❤...;| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^error[E0432]: unresolved import `crate::os::consts`

最终放弃在FreeBSD下使用Tauri 。

http://www.lryc.cn/news/490620.html

相关文章:

  • Django实现智能问答助手-数据库方式读取问题和答案
  • stm32利用LED配置基础寄存器+体验滴答定时器+hal库环境配置
  • JAVA开源项目 桂林旅游景点导游平台 计算机毕业设计
  • docker安装使用Elasticsearch,解决启动后无法访问9200问题
  • GM、BP、LSTM时间预测预测代码
  • 《操作系统 - 清华大学》4 -5:非连续内存分配:页表一反向页表
  • 志愿者小程序源码社区网格志愿者服务小程序php
  • Java语言编程,通过阿里云mongo数据库监控实现数据库的连接池优化
  • 使用ufw配置防火墙,允许特定范围IP访问
  • 实现 UniApp 右上角按钮“扫一扫”功能实战教学
  • 【2024亚太杯亚太赛APMCM C题】数学建模竞赛|宠物行业及相关产业的发展分析与策略|建模过程+完整代码论文全解全析
  • ubtil循环函数调用
  • 使用EFK收集k8s日志
  • 聚水潭与MySQL数据集成案例分享
  • Python 版本的 2024详细代码
  • SpringCloud框架学习(第四部分:Gateway网关)
  • C++ 类和对象 (上 )
  • HAProxy面试题及参考答案(精选80道面试题)
  • 探索PyCaret:一个简化机器学习的全栈库
  • 英语写作中“联系、关联”associate correlate 及associated的用法
  • 深度学习之目标检测的技巧汇总
  • 【Flask+Gunicorn+Nginx】部署目标检测模型API完整解决方案
  • Spark核心组件解析:Executor、RDD与缓存优化
  • “AI玩手机”原理揭秘:大模型驱动的移动端GUI智能体
  • 离散数学【关系】中的一些特殊关系
  • docker 配置代理
  • Dockerfile详解:构建简单高效的容器镜像
  • RHCD-----shell
  • <硬件有关> 内存攒机认知入门,内存的选择 配置 laptop PC 服务器
  • 基于springboot的来访管理系统的设计与实现