rust on android

Is it possible to write a GUI Android app in rust? (self.rust)

submitted 4 months ago by rmc

Hi all,

I‘m new to rust, so forgive me if this is a really simple question, but is it currently possible to write a GUI Android application in Rust?

I have an idea for an Android app, and am tempted to write something in Rust. I see there is documentation on compiling for android, but I read an old thing somewhere that you couldn‘t do GUIs. So is it possible now?

I don‘t want to make a game, just something with regular android buttons/etc.

10 comments
share

all 10 comments
sorted by:
best

[–]cmrx64rust 3 points 4 months ago

You‘ll need to do 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 have in their NDK for C++.

But, https://github.com/tomaka/glutin/blob/master/examples/window.rs works on Android. You can draw to the screen 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-link
parent

[–]mbrubeckservo 7 points 4 months ago*

Yes, that‘s correct.

You have two options:

Write your UI in Java, and use JNI to call functions from a C/Rust/C++/etc. library for things like computations, or

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.

perma-link
parent

[–]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-link
parent

[–]mbrubeckservo 4 points 3 months ago

Yes; to a large extent the Android native development kit is designed with games in mind, and not a very good fit for most other uses. (That‘s not stopping us for using it to test Servo builds, though…)

perma-link
parent

[–]dobkeratopsrustfind 2 points 3 months ago

yes, porting a native code GL game between platforms is easier than porting a platform dependant GUI

perma-link
parent

[–]wupis 2 points 3 months ago

Or write your own automated Java binding generator for Rust!

perma-link
parent

[–]lelarentaka 2 points 4 months ago

If you‘re really into the name: Type syntax, go with Scala.

perma-link
parent

[–]deskamess 2 points 4 months ago

You could also wait and see how Go is going to tackle this. Perhaps you would be able to leverage some of their tooling/approach and make it work once they have something ready. Their approach involves JNI as well so you are not 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 are really good for messages, state machines..). I think people in the piston community might be experimenting in this direction ?

Seems like GUI frameworks are heavily language dependant. apple-verse: objC. Microsoft C(win32) -> C++(MFC) -> C#. 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 virtue 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 is sadly an afterthought on android), but it also declares a lot of what C++ does to be misfeatures hence can have have trouble interfacing with it (not just unsafe, but language philosophy).

eg a while back they tried to port Qt… and those API‘s use overloading. Is the situation any different now? (multiparam traits might help?)

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。