I would like to develop mobile apps for Android/iOS in Rust because Rust is awesome, safe and is the only sane system + application programming language IMO. Sadly, I have no idea where and how I should start. Therefore I researched about frameworks and relatives for that task. I found NativeScript, Phonegap/Cordova, Rubymotion, Xamarin and Djinni.
The approach of Xamarin is the best in my opinion.
They wrote an abstraction layer for the native UI (https://www.xamarin.com/forms).
For access to sensors, camera etc. they have a system called DependencyService. I think it actually wraps platform-native calls (JNI on Android, something in ObjC on iOS).
- ~90% portable code
- Easy to apply UI design (predefined layouts in XAML) which compiles to native UI for the specific platform
- Can’t be used on Linux
- Inherited cons of C#
I’d like to have a similiar framework for Rust.
Questions to solve:
- Language direction: Should the platform-native language invoke Rust code? For example on Android: Java -> Rust code on demand? Or rather: Rust -> some API wrapping Android calls (JNI) -> Java
- According to 1. How do we share data structure between languages if we have to? (C++: Djinni uses its own language for this problem: github.com/dropbox/djinni)
- How can we abstract a Rustic interface over platform calls?
- How do we share threads between languages?
- How do we manage the UI part?
- Which crates would we need to write? Hierarchy?
My opinion to 5.:
I think people should be able to write Rust code at least for the core (in MVVM: Model + ViewModel). For the UI there should be either/and/or:
- an interface in Rust (View also in Rust).
- a way to just put an Android Studio / XCode project over the whole thing (seperate View) .
For (2) the tree directory could look like this:
. ├── Cargo.toml ├── src │ └── main.rs └── ui ├── android <- Android Studio Project └── ios <- XCode Project
To build the app for a specific platform you’d spin up cargo like this:
cargo app iPhone cargo app Android
BTW I don’t have much Rustic and mobile app programming experience. I can’t implement such a big task myself. Are you interested in doing it together?