tauri2-mobile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTauri 2 Mobile Development
Tauri 2 移动开发
Build cross-platform mobile apps with Tauri 2 using web technologies (HTML/CSS/JS) for UI and Rust for native backend.
使用Web技术(HTML/CSS/JS)构建UI,结合Rust作为原生后端,通过Tauri 2开发跨平台移动应用。
Quick Reference
快速参考
| Task | Command |
|---|---|
| Init mobile | |
| Dev Android | |
| Dev iOS | |
| Build APK | |
| Build AAB | |
| Build iOS | |
| Add plugin | |
| 任务 | 命令 |
|---|---|
| 初始化移动项目 | |
| Android开发调试 | |
| iOS开发调试 | |
| 构建APK | |
| 构建AAB | |
| 构建iOS应用 | |
| 添加插件 | |
Workflow Decision Tree
工作流决策树
New Project Setup
新项目搭建
- Read references/setup.md for environment configuration
- Run with mobile targets
npm create tauri-app@latest - Configure with app identifier
tauri.conf.json
- 阅读references/setup.md配置开发环境
- 运行并选择移动目标平台
npm create tauri-app@latest - 在中配置应用标识符
tauri.conf.json
Adding Features
添加功能
- Native functionality: Read references/plugins.md
- Rust commands/state: Read references/rust-patterns.md
- Frontend integration: Read references/frontend-patterns.md
- Authentication/OAuth: Read references/authentication.md
- In-app purchases: Read references/iap.md
- 原生功能:阅读references/plugins.md
- Rust命令/状态管理:阅读references/rust-patterns.md
- 前端集成:阅读references/frontend-patterns.md
- 身份验证/OAuth:阅读references/authentication.md
- 应用内购买:阅读references/iap.md
Testing
测试
- Emulator/ADB debug: Read references/testing.md
- Use for logs
adb logcat | grep -iE "(tauri|RustStdout)"
- 模拟器/ADB调试:阅读references/testing.md
- 使用查看日志
adb logcat | grep -iE "(tauri|RustStdout)"
Building & Deployment
构建与部署
- Code signing & stores: Read references/build-deploy.md
- CI/CD pipelines: Read references/ci-cd.md
- 代码签名与应用商店发布:阅读references/build-deploy.md
- CI/CD流水线:阅读references/ci-cd.md
Project Structure
项目结构
my-app/
├── src/ # Frontend
├── src-tauri/
│ ├── Cargo.toml
│ ├── tauri.conf.json # Main config
│ ├── src/
│ │ ├── main.rs # Desktop entry (don't modify)
│ │ └── lib.rs # Main code + mobile entry
│ ├── capabilities/
│ │ └── default.json # Permissions
│ └── gen/
│ ├── android/ # Android Studio project
│ └── apple/ # Xcode projectmy-app/
├── src/ # 前端代码
├── src-tauri/
│ ├── Cargo.toml
│ ├── tauri.conf.json # 主配置文件
│ ├── src/
│ │ ├── main.rs # 桌面端入口(请勿修改)
│ │ └── lib.rs # 核心代码 + 移动端入口
│ ├── capabilities/
│ │ └── default.json # 权限配置
│ └── gen/
│ ├── android/ # Android Studio项目
│ └── apple/ # Xcode项目Essential Configuration
关键配置
tauri.conf.json
tauri.conf.json
json
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "MyApp",
"identifier": "com.company.myapp",
"bundle": {
"iOS": { "minimumSystemVersion": "14.0" },
"android": { "minSdkVersion": 24 }
}
}json
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "MyApp",
"identifier": "com.company.myapp",
"bundle": {
"iOS": { "minimumSystemVersion": "14.0" },
"android": { "minSdkVersion": 24 }
}
}capabilities/default.json
capabilities/default.json
json
{
"identifier": "default",
"windows": ["main"],
"permissions": ["core:default"]
}json
{
"identifier": "default",
"windows": ["main"],
"permissions": ["core:default"]
}lib.rs (Mobile Entry)
lib.rs(移动端入口)
rust
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_deep_link::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error");
}
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}rust
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_deep_link::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error");
}
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}Common Issues
常见问题
| Problem | Solution |
|---|---|
| White screen | Check JS console, verify |
| iOS won't connect | Use |
| INSTALL_FAILED_ALREADY_EXISTS | |
| Emulator not detected | Verify |
| HMR not working | Configure |
| Shell plugin URL error | Use |
| Google OAuth fails | Google blocks WebView; use system browser flow |
| Deep link not received | Check scheme in tauri.conf.json, init plugin |
| Safe area CSS fails on Android | |
| Windows APK build symlink error | Enable Developer Mode or copy .so files manually |
See references/testing.md for detailed troubleshooting.
| 问题 | 解决方案 |
|---|---|
| 白屏 | 检查JS控制台,验证 |
| iOS无法连接 | 使用 |
| INSTALL_FAILED_ALREADY_EXISTS | 执行 |
| 模拟器未被识别 | 验证 |
| HMR不工作 | 在 |
| Shell插件URL错误 | 改用 |
| Google OAuth失败 | Google屏蔽WebView;使用系统浏览器流程 |
| 未接收深度链接 | 检查tauri.conf.json中的scheme配置,初始化对应插件 |
| Android安全区域CSS失效 | WebView不支持 |
| Windows下APK构建符号链接错误 | 启用开发者模式或手动复制.so文件 |
详细故障排除请查看references/testing.md。
Resources
资源
- Docs: https://v2.tauri.app
- Plugins: https://v2.tauri.app/plugin/
- GitHub: https://github.com/tauri-apps/tauri