Skip to content

Going Mobile: Android and iOS

One of the most revolutionary features of Tauri v2 is the ability to take the exact same web frontend and Rust backend you wrote for your desktop application and run it on mobile devices. This transforms Tauri from a desktop framework into a true cross-platform solution.

Before diving in, ensure you completed the mobile setup steps in Chapter 2. Development for mobile requires heavy platform-specific tools:

  • Android: You need Android Studio and the Android SDK environment variables (JAVA_HOME, ANDROID_HOME) configured.
  • iOS: You need a macOS device with Xcode installed. iOS development is not possible on Windows or Linux.

Tauri does not clutter your project with mobile files by default. You need to explicitly initialize them. This process creates the native project structures (a Gradle project for Android and an Xcode workspace for iOS) inside the src-tauri/gen folder.

Run the following commands in your terminal to scaffold the mobile targets:

Terminal window
tauri android init
tauri ios init

During initialization, the CLI might prompt you to install specific Rust targets (like aarch64-linux-android or aarch64-apple-ios). Allow it to do so.

Once initialized, running your app on a mobile emulator is surprisingly similar to running it on a desktop. The Tauri CLI handles compiling your Rust code into a library, bundling your frontend, and launching the native app.

Terminal window
# For Android Emulator or connected device
tauri android dev
# For iOS Simulator or connected device
tauri ios dev

When you run these commands, Tauri will attempt to find a connected device or a running emulator. If none are found, it may prompt you to select one.

While the code is shared, the user experience (UX) is different. Here are key adjustments to keep in mind:

  • Touch vs. Mouse: There is no ‘hover’ state on mobile. Ensure your UI relies on tap interactions.
  • Safe Areas: Mobile screens have notches and rounded corners. Use CSS environment variables like env(safe-area-inset-top) to prevent your content from being hidden behind the status bar.
  • Backend Limitations: While most standard Rust code works perfectly, crates that rely on specific desktop OS APIs (like interacting with the Windows Registry or Linux X11) will not work on mobile. You may need to use #[cfg(target_os = "android")] to conditionally compile code.

Sometimes you need to configure native settings, such as the App Icon, Launch Screen, or specific permissions (like Camera access in Info.plist or AndroidManifest.xml). Tauri provides a shortcut to open the generated projects in their respective native IDEs:

Terminal window
tauri android open
tauri ios open

This opens Android Studio or Xcode, allowing you to tweak the native layer just as if you were writing a native app.