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?)

时间: 2024-10-09 21:13:30

rust on android的相关文章

Android - Fragment (三)不同Fragment之间的通信

在Fragment的java文件中,可以使用getActivity()来获得调用它的activity, 然后再找到另一个Fragment,进行通信 getActivity().getFragmentManager().findFragmentById(R.id.fragment_list); 但这样做耦合度太高,不方便后续的修改操作 Fragment与其附着的Activity之间的通信,都应该由Activity来完成 不能是多个Fragment之间直接通信 Fragment与其附着的Activi

Android Bitmap 常见的几个操作:缩放,裁剪,旋转,偏移

Android Bitmap 相关操作 常见的几个操作:缩放,裁剪,旋转,偏移      很多操作需要 Matrix 来支持:Matrix 通过矩阵来处理位图,计算出各个像素点的位置,从而把bitmap显示出来. matrix里有一个3x3的矩阵,用于图像处理: MSCALE_X MSKEW_X MTRANS_X MSKEW_Y MSCALE_Y MTRANS_Y MPERSP_0 MPERSP_1 MPERSP_2 根据变量名能猜出具体的用途:缩放X 偏移X 平移X偏移Y 缩放Y 平移Y透视0

Android - Fragment(二)加载Fragment

Fragment加载方法 加载方法有两种,在xml文件中注册,或者是在Java代码中加载. xml中注册 例如在fragment_demo.xml中定义 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width=

Android照片墙应用实现,再多的图片也不怕崩溃

本文首发于CSDN博客,转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9526203 照片墙这种功能现在应该算是挺常见了,在很多应用中你都可以经常看到照片墙的身影.它的设计思路其实也非常简单,用一个GridView控件当作“墙”,然后随着GridView的滚动将一张张照片贴在“墙”上,这些照片可以是手机本地中存储的,也可以是从网上下载的.制作类似于这种的功能的应用,有一个非常重要的问题需要考虑,就是图片资源何时应该释放.因为随着

【Android】Android Studio 1.5+ 中混合调试Native和Java代码

[Android]Android Studio 1.5+ 中调试Native和Java代码 Android Studio 1.5+表示Android Studio 1.5版本以及以上. 网上大部分中文或英语教程还是停留在老版本的Android Studio的Debug的设置,要么不全.正好最近工作中要在Android Studio中调试C++代码,就来写一篇咯. Android Studio 1.5+的调试设置与之前有所不同. 而且新版中推出了一个Hybrid的调试:可以混合调试Native代码

Rust 功能函数的关系、包和模块简介

Rust 功能函数的关系.包和模块简介 一.功能函数之间的关系 前面看到,一个文件中可以定义多个 function 功能函数,这些功能函数可以被相互使用.程序的入口是main(). 在一个文件中,各个功能函数的定义和使用不受功能函数定义的顺序约束.也就是说,不需要像 C 语言一样,在使用一个函数而还没有定义函数之前要有一个声明语句:而像 java 一样,只要声明的功能函数在一个文件内,可以忽略功能函数在文件中出现的顺序. 二.文件的包管理 当一个文件中的功能函数越来越多,阅读和修改都是个问题.因

Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

转载请注明出处http://blog.csdn.net/xiaanming/article/details/9825113 异步加载图片的例子,网上也比较多,大部分用了HashMap<String, SoftReference<Drawable>> imageCache ,但是现在已经不再推荐使用这种方式了,因为从 Android 2.3 (API Level 9)开始,垃圾回收器会更倾向于回收持有软引用或弱引用的对象,这让软引用和弱引用变得不再可靠.另外,Android 3.0

Rust Attribute的十三个分类包含的注释

Rust 的 Attribute 注释到目前为止(当前版本 rustc 1.7.0 (a5d1e7a59 2016-02-29)一共包括十三个种类. 一.只用于 crate 的 attribute crate_name - specify the crate's crate name. crate_type - see linkage. feature - see compiler features. no_builtins - disable optimizing certain code p

2. Rust的三板斧 安全,迅速,并发

Rust不是一个拥有前沿科技的革命性语言,但是Rust合并了已经在老的语言中证明了自己的技术.当然它在c++的基础上大大的提升安全性. Rust的开发者,设计Rust成为通用的有大量实例的语言.就像C++,他是结构化的面向对象语言.除了这一点,它从现有的语言中集合和继承了许多先进的技术. 在Rust中,输入变量是静态和强壮的因为Rust已经被编译好. 但是,不像java和C++,开发者不用强制去制定所有实物的类型,Rust的编译器在很多情况下可以推测类型. C和C++中,有被人熟知的一系列问题会