rust on android

來源:互聯網
上載者:User

標籤:

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 commentsshare

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-linkparent

[–]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, 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 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-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 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?)

rust on android

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.