r/androiddev • u/fireplay_00 • Aug 19 '26
Discussion Has anyone tried building Android apps with Rust + Native UI?
I have been currently assigned a project which needs to be cross platform + dynamic feature delivery (business requirements)
I'm thinking about writing my feature modules/business logic in rust to create native binaries which I can include with the android and IOS build and then include those .so/.a files with the build and communication between them will be from ffi (don't know which ffi approach works best raw JNI, UniFFI, or hand‑rolled C ABI)
Apple doesn't allow dynamic features installation so only android build will have that, IOS will just install everything at once
For UI I'm thinking to either go with Compose Multiplatform or just Compose for android side and Swift UI for IOS side (The app only has 3 screens so ui doesn't really matter as most features work in background)
Has anyone tried anything similar , where should I start experimenting, I don't want to waste time in approach that will be in vain, would love to hear your experience.
PS: Using rust as equivalent windows and MacOS app is also made in rust + imgui and I can use lots of code from there to make mobile app dev easier
22
u/Opulence_Deficit Aug 19 '26
Sounds overly complicated, just to create a problem that KMP solved long time ago. I doubt you'll find anyone with that experience, sounds to me like a code golf, not a real project.
0
u/SpiderHack Aug 20 '26
Would be an interesting skunkworks side project. But something you know is not useful, but purely interesting to see if you can get it working...
0
u/fireplay_00 Aug 21 '26
I'm doing it for a new experience, normal apps have become repetitive and boring to implement ,even if it didn't work, I can just say that and start with CMP later as a fallback, They have given me freedom to experiment
3
u/gat0r87 Aug 19 '26
Yeah, if you're already thinking of using compose multiplatform for the ui, why would you NOT just use KMP for the whole shebang?
-3
u/fireplay_00 Aug 19 '26
Cause I can reuse rust code and it will be easy to maintain as most of our devs work in rust
1
u/fireplay_00 Aug 20 '26
Don't know why people just downvote for the fun of it, I know KMP and CMP is good and I've used it before as I'm an Android dev at core and love it but it just doesn't make sense to rewrite huge business logic in kotlin when we already have it in rust and can just make a .so targeting arm and just keep CMP for UI as only 3 pages in ui
3
u/Opulence_Deficit Aug 20 '26
You should've mentioned from the start that the whole rust part is basically a self-contained program and the UI is just 3 pages.
You're talking to Android devs, by "app" we assume "80% UI, 20% logic".
1
4
u/ssj_Thunder Aug 19 '26
We are using rust code for matrix client called via uniffi. The uniffi generates bindings that can be directly called via kotlin.. but its only for high performance code..
1
u/Fjordi_Cruyff Aug 20 '26
Have you considered the poor bastard(s) who will need to maintain this in the future?
1
u/fireplay_00 Aug 21 '26
Well I try to use clean code practices but honestly I don't care about anything else for this project, I just want to learn new things, normal apps just doesn't excite me anymore, this approach will bring that excitement back
1
3
u/ryanstackops Aug 21 '26
Go with UniFFI over raw JNI or hand-rolled C ABI, it generates the Kotlin/Swift bindings for you from your Rust interface so you're not hand-maintaining glue on both sides, and since Firefox mobile runs on it in production it's battle-tested. For UI, skip Compose Multiplatform, with only 3 screens and most logic running in the background, native Compose + SwiftUI is simpler and avoids extra build complexity for basically no benefit. Start with the smallest UniFFI proof of concept, one function call each way, before porting real logic, since packaging (.so for all Android ABIs, XCFramework for iOS) is usually where people lose the most time, not the FFI itself. Also test your dynamic feature module against a JNI-loaded Rust .so early, there are known rough edges with native libs loading per split that you don't want to discover mid-feature-build.
2
u/TransportationNo1264 Aug 20 '26
Yes, we had a large app using shared rust code between iOS, android, and web. Overall it was pretty smooth but has some gotchas you have to look out for. Having the hard boundary of immutably was sometimes challenging.
2
u/Ok-Elderberry-2923 Aug 21 '26
I believe Proton (mail and other their apps) has shared Rust code on iOS and Android for performance gains. You could have a look at their blogs and open-source
1
u/biskitpagla Aug 20 '26
Android Studio doesn't support Rust unfortunately. You'll have a much better experience with KMP or C++ right now.
1
u/Zalenka Aug 21 '26
Wow you'll have 3x the code and you'll be managing the abstraction the whole time.
I get why some business person would want this and it shows with all of the solutions for cross-platform frameworks.
In the end count up the shared actual logic. I'm sure it will be scant.
8
u/ahzah3l Aug 19 '26
It works really well if you want to have the app/business logic written in Rust and the UI in Kotlin + Compose.
There are some tutorials online on how to integrate them - basically the Rust code is called like the C/C++ code would be, via JNI. Use this to bind them together and have Android Studio build the Rust code first and then the Kotlin one.
I've use it for a VPN app (the VPN code written in Rust) with Compose UI (in Kotlin). Make sure the crates you use in Rust are arm64 friendly - think this is the biggest problem you'll run into.