If you have a desktop Tauri project and want to target mobile platforms using the same code, you must configure your Rust crate.
The Rust crate must output a library that will be embedded in the Android and iOS packages. Add the following section to your
The default entry point for the Rust library is the
Let’s write a
tauri::Builder wrapper that will be reused by both the desktop and mobile targets.
In this example, the
AppBuilder::run function is where you write all the shared logic. Custom mobile/desktop code can be defined in the AppBuilder methods, such as the setup method.
Now let’s create the mobile module that will have the entry point for iOS and Android and consume the shared AppBuilder logic:
The default Tauri project has the binary source code under
src-tauri/src/main.rs. Let’s change it to use the AppBuilder struct:
To develop mobile Tauri applications, your frontend must serve the assets listening on your public network address.
The network address can be found using the
Then you need to configure your framework to use the internal IP.
For Vite, you need to change your configuration to be defined using the
defineConfig helper with an async closure.
Then, resolve the internal IP address and set it to the server object.
For Next.js, you need to configure the assetPrefix to use the internal IP so the server properly resolves your assets.
Currently, there is no configuration option to configure Next.js to use the internal IP address, only the CLI allows changing it.
So you need to append
--hostname $HOST to the beforeDevCommand.
Webpack has a built-in option to use the local IP address as the host for the development server:
#[cfg(mobile)] conditional checks can be used to conditionally compile code for each target.
© 2024 Tauri Contributors. CC-BY / MIT