cargo-mobile2 技术文档

cargo-mobile2 技术文档

cargo-mobile2 Rust on mobile made easy! cargo-mobile2 项目地址: https://gitcode.com/gh_mirrors/ca/cargo-mobile2

安装指南

系统要求

cargo-mobile2 目前支持 macOS、Linux 和 Windows 系统。需要注意的是,iOS 只能在 macOS 上进行编译和运行。无论在哪个平台上,你都可以编译和运行 Android 应用。

安装步骤

  1. 安装依赖

    • 确保你已经安装了 Xcode(仅限 macOS)和 Android SDK/NDK。
    • 未来可能会自动化这些步骤,或者提供详细的安装指南和诊断工具。
  2. 安装 cargo-mobile2: 打开终端并运行以下命令:

    cargo install --git https://github.com/tauri-apps/cargo-mobile2
    

    安装过程可能需要一些时间,你可以趁此机会休息一下。

  3. 更新 cargo-mobile2: 如果你想更新 cargo-mobile2,可以运行以下命令:

    cargo mobile update
    

项目的使用说明

创建新项目

  1. 创建项目目录: 创建一个新的目录,并进入该目录:

    mkdir my_project
    cd my_project
    
  2. 初始化项目: 运行以下命令来初始化项目:

    cargo mobile init
    

    系统会提示你选择一个模板包。模板包用于生成项目的基本代码结构。例如,选择 wry 模板包会生成一个基于 wry 的项目,该项目可以在桌面和移动设备上直接运行。

    | 模板名称 | 说明 | | -------- | -------------------------------------------------------------------- | | wry | 最小化的 wry 项目 | | egui | 基于 agdk-egui example 的完整 egui + winit + wgpu 示例 |

    注意:目前 bevy 模板存在编译问题,不建议使用。

运行项目

  • 桌面运行: 使用 cargo run 命令可以在桌面环境中运行你的应用。

  • 移动设备运行: 使用 cargo apple run 命令可以在连接的 iOS 设备上运行应用,使用 cargo android run 命令可以在连接的 Android 设备上运行应用。

  • IDE 支持: 使用 cargo apple open 命令可以在 Xcode 中打开项目,使用 cargo android open 命令可以在 Android Studio 中打开项目。

更多命令

运行 cargo mobilecargo applecargo android 命令可以查看更多帮助信息。

项目API使用文档

Android 运行命令

  • 基本运行: 使用 cargo android run 命令可以构建、安装并运行应用,并查看设备日志。

  • 日志级别控制: 默认情况下,只显示警告和错误日志。你可以通过 -v-vv 选项增加日志的详细程度。

  • 自定义日志过滤: 使用 --filter-f 选项可以指定日志级别,例如 debug。该选项会覆盖 -v-vv 设置的默认日志级别。

  • Rust 日志映射: 如果使用 android_logger crate 处理 Rust 日志消息,Rust 中的 trace 日志会映射到 Android 的 verbose 日志级别。

项目安装方式

安装 cargo-mobile2

通过以下命令安装 cargo-mobile2:

cargo install --git https://github.com/tauri-apps/cargo-mobile2

更新 cargo-mobile2

通过以下命令更新 cargo-mobile2:

cargo mobile update

通过以上步骤,你可以顺利安装并使用 cargo-mobile2 来开发跨平台的 Rust 应用。

cargo-mobile2 Rust on mobile made easy! cargo-mobile2 项目地址: https://gitcode.com/gh_mirrors/ca/cargo-mobile2

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

武晔研Dillon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值