Live data from Hacker News

Bare-metal Rust in Android

security.googleblog.com

31–40 of 124 posts

Re: Bare-metal Rust in Android

#31
post #12

Earlier quoted context omitted.

Not having to use Java or any of its weird derivatives.

I implore you to try Kotlin; it’s a fantastic language and is a wonder to code in

I implore you to try Rust.

Kotlin is just Java with extra steps.

Re: Bare-metal Rust in Android

#33
post #11

Ok, now enable us to let create Android Applications entirely in Rust (including the GUI). Let's get rid of Kotlin/Java monopoly in Android App development. Shall we?

You can technically create an Android app without any Java code. There are native APIs for graphics and input. However, as these are intended for games, you get a window into which you can draw... something. With OpenGL, for example. You don't get access to Android's regular UI framework. You will also have to go through the Java layer to do many things you might want to do — like requesting permissions or launching…

You can also "outsource" the Java based interaction with Android to somebody else, Qt style? https://doc.qt.io/qt-6/android-getting-started.html

Re: Bare-metal Rust in Android

#34

Ok, now enable us to let create Android Applications entirely in Rust (including the GUI). Let's get rid of Kotlin/Java monopoly in Android App development. Shall we?

Tell me you've never done any Android development, without telling me... This is such a low-effort "take" without any effort to justify _why_ you'd want something like this. There's a high amount of impedance mismatch trying to write GUIs in a non-GC language like Rust which _has_ to run on what's essentially a Java VM (ART). At least with a language like Go, it somewhat makes sense, and has been attempted: https://g…

> At least with a language like Go, it somewhat makes sense, and has been attempted: https://gioui.org/

Gio UI is an immediate-mode UI, and immediate-mode UIs map very nicely to Rust. egui is quite expressive and easy to use. https://www.egui.rs/

If you had pointed at something like GTK, then yes, there is a big impedance mismatch there.

Re: Bare-metal Rust in Android

#35
post #6

Earlier quoted context omitted.

What would rust achieve aside from just enabling another, entirely distinct from the existing workflow, language? Haven’t android apps been compiled to native code since like 2012? (I actually don’t know, I left android a while ago and stopped caring what they do)

I don't think it's a good idea, mainly because android is multiplatform and rust, by it's nature, is only available for what it's built for. Unless you are giving google your rust code to compile, your app will be limited on it's reach. All that said. Rust doesn't have a GC so it'd (likely) have a lower memory consumption and could possibly be lighter on the CPU. Native compilation helps mainly with startup time and…

> Unless you are giving google your rust code to compile, your app will be limited on it's reach.

Android has supported native code in apps for a long time via the Android NDK, mainly to enable game development. The Android team seems to hate the NDK, but the alternative is to have no games on the platform, so they can't simply kill it.

> ...[native] ... It's not exactly great for runtime performance as it takes away some key optimizations.

In theory a JIT might produce better runtime performance than AOT compiled code, but in practice that usually turns out as wishful thinking.

Re: Bare-metal Rust in Android

#37

Ok, now enable us to let create Android Applications entirely in Rust (including the GUI). Let's get rid of Kotlin/Java monopoly in Android App development. Shall we?

Isn't this what Tauri wants to achieve? At least it's on the roadmap I mean. https://tauri.app/ Does anyone have any experience creating production apps with Tauri? Seems like a sane alternative to Electron, especially if they can target all major platforms and keep the promise of smaller footprints.

The traditional alternative to Electron on mobile platforms is Capacitor (which uses the system webview, so in that sense it's closer to Tauri):

https://capacitorjs.com/

(fka Apache Cordova, fka PhoneGap)

Re: Bare-metal Rust in Android

#38
post #11

Ok, now enable us to let create Android Applications entirely in Rust (including the GUI). Let's get rid of Kotlin/Java monopoly in Android App development. Shall we?

You can technically create an Android app without any Java code. There are native APIs for graphics and input. However, as these are intended for games, you get a window into which you can draw... something. With OpenGL, for example. You don't get access to Android's regular UI framework. You will also have to go through the Java layer to do many things you might want to do — like requesting permissions or launching…

You can call into any Android Java API from native code using JNI. It's not exactly convenient, but you are not limited to the C APIs exposed by the NDK.

Re: Bare-metal Rust in Android

#39

Earlier quoted context omitted.

I don't think it's a good idea, mainly because android is multiplatform and rust, by it's nature, is only available for what it's built for. Unless you are giving google your rust code to compile, your app will be limited on it's reach. All that said. Rust doesn't have a GC so it'd (likely) have a lower memory consumption and could possibly be lighter on the CPU. Native compilation helps mainly with startup time and…

>mainly because android is multiplatform and rust, by it's nature, is only available for what it's built for Android is one platform: android. I thought rust worked across multiple operating systems. >Rust doesn't have a GC so it'd (likely) have a lower memory consumption and could possibly be lighter on the CPU. So what? I have never used G.C. >Native compilation helps mainly with startup time and memory consumption…

> Android is one platform: android. I thought rust worked across multiple operating systems.

Operating systems, not architectures. You'd have to cross-compile your application 4 times if you want to support all arms and x86s.

> I think the main benefit of rust/c++/ndk on android is that I can just port desktop programs and I don't have to learn android's java/kotlin and sdk.

It's not "just" port desktop programs. Android doesn't even use glibc.

Post reply on HN