First install cargo-mobile2
cargo install cargo-mobile2
Then install and add the Android SDK and NDK for your platform to your path.
Start by creating a new crate and adding the required dependencies:
cargo new my_app
cd my_app
cargo add dioxus
cargo add dioxus-blitz --git https://github.com/DioxusLabs/blitz
Then initialize cargo-mobile2
cargo mobile init
Current issues
cargo-mobile2 currently has an issue compiling with newer versions of Gradle (tauri-apps/cargo-mobile2#392) but this should be fixed soon in tauri-apps/cargo-mobile2#404.
For now you can remove lines 42-44 in gen/android/app/build.gradle.kts:
kotlinOptions {
jvmTarget = "1.8"
}
Now you're ready to start writing your Dioxus application:
use dioxus::prelude::*;
fn app() -> Element {
rsx!{ h1 { "Hello, World!" } }
}
#[no_mangle]
fn android_main(android_app: android_activity::AndroidApp) {
dioxus_blitz::set_android_app(android_app);
dioxus_blitz::launch(app);
}Finally connect your device in debugging mode, or startup a simulator in Android Studio, and run:
cargo android run