Is it possible to write a GUI Android apps in rust? (Self.rust)
Submitted 4 months ago by RMC
Hi all,
I ' m new to rust, so forgive me if it's a really simple question, but was it currently possible to write a GUI Android AP Plication in Rust?
I have a idea for Android app, and am tempted to write something in Rust. I see there are documentation on compiling for Android, but I read a old thing somewhere so you couldn ' t do GUIs. So are it possible now?
I don ' t want to make a game, just something with regular Android buttons/etc.
10 commentsshare
All ten comments
Sorted by:
Best
[–]cmrx64rust 3 points 4 months ago
You'll need to does a lot of JNI to integrate as a normal Android app, and you ' re going to lose any advantage of using Rust. Just use Java. See also http://developer.android.com/reference/android/app/NativeActivity.html for what they has in their NDK for C + +.
But, https://github.com/tomaka/glutin/blob/master/examples/window.rs works on Android. You can draw to the screens with OpenGL ES. You just don't get access to the rest of the Android SDK.
perma-link
[–]zokier 7 points 4 months ago
To clarify, isn ' t it pretty much the same situation as with C (or any Non-java language for that matter)?
perma-linkparent
[–]mbrubeckservo 7 points 4 months ago*
Yes, that ' s correct.
You have the options:
Write your UI in Java, and use JNI to call functions from a C/Rust/C++/etc. library for things like computations, orwrite your whole app in C/Rust/C++/etc. using OpenGL to draw to a full-screen window, without using any of the Android UI framework.perma-linkparent
[–]rmc[s] 4 points 4 months ago
write your whole app in C/Rust/C++/etc. using OpenGL to draw to a full-screen window, without using any of the Android UI framework.
Sounds like writing an android game in Rust is easier than writing a non-game application! :P
perma-linkparent
[–]mbrubeckservo 4 points 3 months ago
Yes; To a large extent the Android native development Kit are designed with games in mind, and not a very good fit for most othe R uses. (That's not stopping us for using it to test Servo builds, though ...)
perma-linkparent
[–]dobkeratopsrustfind 2 points 3 months ago
Yes, porting a native code GL game between platforms is easier than porting a platform dependant GUI
perma-linkparent
[–]wupis 2 points 3 months ago
Or Write your own automated Java binding generator for rust!
perma-linkparent
[–]lelarentaka 2 points 4 months ago
If you ' re really into the name:type syntax, go with Scala.
perma-linkparent
[–]deskamess 2 points 4 months ago
You could also wait and see how Go are going to tackle this. Perhaps you would is able to leverage some of their tooling/approach and make it work once they has something ready. Their approach involves JNI as well and you aren't going to work around that aspect. https://docs.google.com/document/d/1N3XyVkAP8nmWjASz8L_OjjnjVKxgeVBjIsTr5qIUcA4/edit?pli=1#
perma-link
[–]dobkeratopsrustfind 2 points 3 months ago*
Rust would really need a GUI library designed around its ' ideas (enums is really good for messages, state machines ...). I think people in the piston community might is experimenting in this direction?
Seems like GUI frameworks is heavily language dependant. APPLE-VERSE:OBJC. C # C + + (MFC), Microsoft C (Win32). Android-java. Web:javascript/dom.
In these examples, new languages (e.g. Objc->swift, c#->f#, Java->scala) use their platforms existing GUI's by VI Rtue of being designed around the underlying system of the language the GUI was designed for.
Rust being "native code" is closest to C + + (use of which are sadly an afterthought on Android), but it also declares a lot of what C + + does to is misfeatures hence can have the trouble interfacing with it (not just unsafe, but language philosop hy).
Eg a while the back they tried to port Qt ... and those API ' s use overloading. is the situation any different now? (Multiparam traits might help?)
Rust on Android