# Mobile Setup Guide (Tauri 2.0) ## Prerequisites ### iOS Development - macOS computer - Xcode 15+ installed - iOS Simulator or physical device - Apple Developer Account (for device testing) ### Android Development - Android Studio installed - Android SDK Platform Tools - Android device or emulator (API level 24+) ## Project Configuration ### Add Mobile Targets to tauri.conf.json ```json { "bundle": { "active": true, "targets": ["all"], "iOS": { "developmentTeam": "YOUR_TEAM_ID", "frameworks": [] }, "android": { "minSdkVersion": 24 } } } ``` ### Install Rust Targets ```bash # iOS targets rustup target add aarch64-apple-ios rustup target add aarch64-apple-ios-sim # Android targets rustup target add aarch64-linux-android rustup target add armv7-linux-androideabi rustup target add i686-linux-android rustup target add x86_64-linux-android ``` ## iOS Setup ### 1. Configure Xcode ```bash # Open Xcode project open ios/Runner.xcworkspace # Or generate Xcode project if needed npm run tauri ios init ``` ### 2. Set Development Team In Xcode: 1. Select the project in the navigator 2. Choose "Signing & Capabilities" 3. Set "Team" to your development team 4. Enable "Automatically manage signing" ### 3. Run on iOS Simulator ```bash # Start development npm run tauri ios dev # Or build for iOS npm run tauri ios build ``` ### 4. Run on Physical Device Connect device via USB, then: ```bash npm run tauri ios dev ``` Select your device when prompted. ## Android Setup ### 1. Install Android SDK ```bash # Via Android Studio SDK Manager # Or via command line sdkmanager "platform-tools" "platforms;android-33" ``` ### 2. Enable USB Debugging On Android device: 1. Settings → About Phone 2. Tap "Build Number" 7 times to enable Developer Options 3. Settings → Developer Options 4. Enable "USB Debugging" ### 3. Connect Device ```bash # Verify device is connected adb devices # Run on Android device npm run tauri android dev ``` ### 4. Android Studio Configuration ```bash # Open Android project open android/` # Or generate project npm run tauri android init ``` ## Mobile-Specific Considerations ### Permissions Add to `android/app/src/main/AndroidManifest.xml`: ```xml ``` Add to `ios/Runner/Info.plist`: ```xml NSCameraUsageDescription We need camera access ``` ### Platform-Specific Code ```rust #[cfg(target_os = "android")] fn mobile_only_android() { println!("Android specific code"); } #[cfg(target_os = "ios")] fn mobile_only_ios() { println!("iOS specific code"); } #[cfg(not(any(target_os = "android", target_os = "ios")))] fn desktop_only() { println!("Desktop specific code"); } ``` ### Mobile Plugins Tauri 2.0 plugins work on mobile: ```typescript // Works on all platforms import { readTextFile } from '@tauri-apps/plugin-fs'; import { fetch } from '@tauri-apps/plugin-http'; import { open } from '@tauri-apps/plugin-shell'; // Mobile-specific import { vibrate } from '@tauri-apps/plugin-haptics'; ``` ### Orientation Control ```rust use tauri::{Manager, AppHandle}; #[tauri::command] fn set_orientation(app_handle: AppHandle, orientation: &str) { #[cfg(target_os = "android")] { use jni::{JNIEnv, objects::JClass, objects::JObject}; app_handle.android().run_on_android_thread( |env, activity| { // Set orientation via Android API }, |error| { eprintln!("Error setting orientation: {}", error); } ); } #[cfg(target_os = "ios")] { // iOS orientation handling } } ``` ## Building for Production ### iOS Production Build ```bash # Archive and export npm run tauri ios build # Sign with distribution certificate # Configure in Xcode → Signing & Capabilities ``` ### Android Production Build ```bash # Generate APK npm run tauri android build # Generate AAB for Play Store # Configure in android/app/build.gradle ``` ## Testing on Mobile ### iOS Simulator ```bash # List available simulators xcrun simctl list devices # Boot specific simulator xcrun simctl boot "iPhone 15" # Run on simulator npm run tauri ios dev ``` ### Android Emulator ```bash # List emulators emulator -list-avds # Start emulator emulator -avd # Run on emulator npm run tauri android dev ``` ## Common Issues **"Team not set" error:** - Set development team in Xcode - Enable automatic signing **"Device not found" (Android):** - Enable USB debugging - Install OEM drivers - Try different USB cable/port **"Provisioning profile error" (iOS):** - Add device to Apple Developer account - Update provisioning profiles **Build fails with linking errors:** - Ensure all Rust targets installed - Clean build: `cargo clean` - Rebuild project ## Mobile Best Practices 1. **Test on real devices** - Simulators don't catch all issues 2. **Optimize bundle size** - Mobile has more constraints 3. **Handle permissions** - Request at appropriate times 4. **Test offline** - Mobile devices have intermittent connectivity 5. **Consider battery** - Avoid constant background operations 6. **Use platform idioms** - Follow iOS/Android design guidelines 7. **Test screen sizes** - Various device form factors 8. **Handle orientation** - Portrait and landscape