News for hackers. Stuff that matters.
Re:Bare-metal Rust in Android by ireallywantthat on Monday October 09, 2023 @02:45PM (#37823763)
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?
Re:Bare-metal Rust in Android by rohandhruva on Monday October 09, 2023 @03:27PM (#37824295)
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://gioui.org/

All this Java/Kotlin bashing is getting really old, especially for a forum like this one.

Re:Bare-metal Rust in Android by ireallywantthat on Monday October 09, 2023 @03:40PM (#37824488)
I didn't bash Java/Kotlin. In fact, I have written few android apps in Kotlin, Java and I also have fiddled with Jetpack compose, JNI and NDK (I have also played with mpv's Opengl/Vulkan's rendering on Android if that matters to you). I don't want to share the projects of mine because i don't want to reveal my identity.

> https://gioui.org/

I know that tailscale's android application is written in it but i don't think gioui is great for android apps.

> Tell me you've never done any Android development, without telling me...All this Java/Kotlin bashing is getting really old, especially for a forum like this one.

Ok, this one hurts. Why are you attacking me instead of defending your stance. All are allowed to have opinions and I am allowed to have one(It's sad to explain this to someone on forum like this one). I dream of Linux-desktop kinda situation where you can program in any language you want, where you are not hindered by any platform/framework, where you have complete freedom and where you don't want to be bothered/(vendor locked-in) by Bigcorps(looking at you Google services framework).

> write GUIs in a non-GC language like Rust which _has_ to run on what's essentially a Java VM (ART).

Haha, non-GC languages power the GUIs on Android fyi. Jetpack compose is powered by Skia. Chromium is powered by Skia. Skia is C++.

Please do your own research before commenting low-effort replies.

Re:Bare-metal Rust in Android by izacus on Monday October 09, 2023 @06:13PM (#37826122)
He's attacking you because you're spewing things that are fundamentally misguided without even seeming to try to look at basic structure of how Android is put together.

Show some basic ability if you want people to engage with your takes, there's already too much ignorant opinions spewed out with assumed authority on this site.

Re:Bare-metal Rust in Android by rohandhruva on Monday October 09, 2023 @08:21PM (#37827121)
> Haha, non-GC languages power the GUIs on Android fyi. Jetpack compose is powered by Skia. Chromium is powered by Skia. Skia is C++.

Skia is not something you use to write apps: it's a graphics engine, essentially something you use to draw polygons on the screen.

> Why are you attacking me instead of defending your stance. All are allowed to have opinions and I am allowed to have one

I apologize if any of this sounded like an attack. I was trying to be funny with that meme-like sentence formation, but I don't profess to disparage anyone's skills or opinions.

> I dream of Linux-desktop kinda situation where you can program in any language you want, where you are not hindered by any platform/framework, where you have complete freedom

Linux desktop is certainly not the dream world you describe. Practically, you _have_ to pick a toolkit: one of GTK / KDE / Qt / electron / etc. Maybe it helps to think of Android's toolkit (Views or Compose) as one of those.

Re:Bare-metal Rust in Android by ireallywantthat on Tuesday October 10, 2023 @03:30AM (#37829417)
> Skia is not something you use to write apps: it's a graphics engine, essentially something you use to draw polygons on the screen.

So, AOSP team can obviously create Rust framework ontop of Skia(or tinyskia,femtovg,etc.), make Android APIs available in Rust, Create proper widget framework and let us create Android Applications written entirely in Rust.

> Linux desktop is certainly not the dream world you describe. Practically, you _have_ to pick a toolkit: one of GTK / KDE / Qt / electron / etc. Maybe it helps to think of Android's toolkit (Views or Compose) as one of those.

I know what I am talking about. This is exactly the freedom that I was talking about. I am able to choose any framework/toolkit I want. If i don't want any framework, that's fine too. You don't have that freedom in Android. Everything has to be routed via Java ecosystem that AOSP constructed.

Re:Bare-metal Rust in Android by pjmlp on Tuesday October 10, 2023 @02:19AM (#37829056)
Calm down with that "Haha", all those native libraries powering Android are behind JNI walls, and even NDK code is obliged to make use of JNI to call into them.

Please do your own research on how AOSP is actually implemented.

Re:Bare-metal Rust in Android by ireallywantthat on Tuesday October 10, 2023 @03:24AM (#37829391)
Calmed down.

> behind JNI walls, and even NDK code is obliged to make use of JNI to call into them.

What i originally told was "enable us to let create Android Applications entirely in Rust (including the GUI)" . Surely Google and AOSP projects can remove the restrictions that you mentioned and provide us alternative to Kotlin/Java ecosystem which is what i really want and hope them to do. Smartphones powered by Android are capable computers and freedom for App development is appreciated.

Please don't mention once again that "X is not implemented in AOSP. Y is required to make use of JNI calls into them". You know that this is superficial barrier and can be overcome/corrected if they wanted to.

Re:Bare-metal Rust in Android by pjmlp on Tuesday October 10, 2023 @03:39AM (#37829477)
If you want freedom for app development buy a Pinephone or Librem 5 device.

Android Brillo demise already proved that isn't what Google cares about.

Re:Bare-metal Rust in Android by voxl on Monday October 09, 2023 @03:41PM (#37824499)
What does a GC have anything to do with it? You can reference count all the pointers if you want, you can expose JVM pointers in Rust where Rust doesn't manage the heap memory. There are plenty of easy solutions to work with the JVM
Re:Bare-metal Rust in Android by ncruces on Monday October 09, 2023 @05:17PM (#37825624)
If you're willing to work with the JVM (i.e. through JNI), there's really nothing stopping you.

You can 100% make entire apps using nothing but C, C++, or whatever, as long as you're willing interface with the JVM that's created for you to access Android APIs.

But the Android API is a JVM API. There's no getting around that. At this point, it's another OS (i.e. not Android) if it doesn't have Java in it.

Re:Bare-metal Rust in Android by pjmlp on Tuesday October 10, 2023 @02:22AM (#37829066)
Actually there was such OS, Android Brillo and the OEM market said no, hence why it got replaced with Android Things, which re-introduced Java again.
Re:Bare-metal Rust in Android by ForkMeOnTinder on Monday October 09, 2023 @04:34PM (#37825160)
> 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 by jeroenhd on Monday October 09, 2023 @05:19PM (#37825642)
There's a reason Chrome is mostly written in C++. Android's JVM system is a collection of Java wrappers around C++ libraries. There's some overhead in that translation layer, and it's unfortunate that you can't skip it. Even Google's own Flutter uses a C++ engine to run Dart applications.

Kotlin (and Java) is fast enough for many applications, but even with the recent advancements in ART, does have overhead compared to pure native code. I can't think of a reason why the API interaction overhead would pose a problem, but if Google themselves can find use cases for almost JVM-less apps, I'm sure there are reasons to give a Rust version a try.

Re:Bare-metal Rust in Android by izacus on Monday October 09, 2023 @06:11PM (#37826106)
> Android's JVM system is a collection of Java wrappers around C++ libraries.

This isn't even remotely true and it's obvious if you'd ever looked closely at Android. This take is as bizarre as saying that whole web/JS/React ecosystem is "just" wrappers on top of Skia.

Re:Bare-metal Rust in Android by rohandhruva on Monday October 09, 2023 @08:13PM (#37827065)
> There's a reason Chrome is mostly written in C++.

And for that same reason, you don't see many apps do the same thing. Any time Chrome needs to request a permission (access files, location, etc), it _has_ to use the system-provided Java APIs.

> Even Google's own Flutter uses a C++ engine to run Dart applications.

As do most games, so you can essentially think of Flutter as a game engine that renders apps.

> Android's JVM system is a collection of Java wrappers around C++ libraries.

As others have mentioned, this is very much not the case.

Re:Bare-metal Rust in Android by ireallywantthat on Tuesday October 10, 2023 @03:31AM (#37829426)
> it _has_ to use the system-provided Java APIs.

My original comment was against this. Why should this be the case?

Re:Bare-metal Rust in Android by diogenes4 on Monday October 09, 2023 @11:01PM (#37828079)
> There's a reason Chrome is mostly written in C++

Yea, security is not a concern. Apparently.

Re:Bare-metal Rust in Android by tempaccount420 on Tuesday October 10, 2023 @07:24AM (#37830746)
They didn't have Rust around when they started.
Re:Bare-metal Rust in Android by diogenes4 on Tuesday October 10, 2023 @02:42PM (#37835821)
That doesn't change anything. Security was simply never what chrome (or webkit to be fair) was built around compared to speed of the insanely inefficient browser stack.
Re:Bare-metal Rust in Android by kaba0 on Tuesday October 10, 2023 @05:30AM (#37830054)
At the same time, GUIs really don’t work nicely/as idiomatically without a GC. Most Rust GUIs do immediate mode only, which is a much more easier problem, and you won’t have to “argue” with the borrow checker constantly. But it would drain the battery of a phone in an hour (it would be the equivalent of running a proper 3D game as your notes app or whatever).
Re:Bare-metal Rust in Android by diogenes4 on Monday October 09, 2023 @11:00PM (#37828075)
> There's a high amount of impedance mismatch trying to write GUIs in a non-GC language like Rust

Sorry, what does the idea of a user interface have to do with garbage collection? They seem entirely unrelated at first blush, and it's not difficult to find GUI code written in rust.

Re:Bare-metal Rust in Android by kaba0 on Tuesday October 10, 2023 @05:33AM (#37830063)
Immediate mode vs retained mode. It is not a hard requirement, but the borrow checker definitely makes the latter more complex.
Re:Bare-metal Rust in Android by grishka on Monday October 09, 2023 @03:08PM (#37824034)
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 other apps' activities.

Here's all the APIs you get: https://developer.android.com/ndk/reference?hl=en

Re:Bare-metal Rust in Android by nologic01 on Monday October 09, 2023 @04:27PM (#37825081)
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 by flohofwoe on Monday October 09, 2023 @04:48PM (#37825307)
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 by grishka on Monday October 09, 2023 @05:12PM (#37825544)
Many Android APIs expect you to extend classes and implement interfaces for things like callbacks. You can't do that with JNI alone, you will have to have a .dex of your own anyway.
Re:Bare-metal Rust in Android by izacus on Monday October 09, 2023 @06:08PM (#37826077)
That's not really what's going on. Those "native" APIs you mention in most cases just call back to Java APIs under the hood. For better or worse, most of what Android is is written in Java. There's no hidden "C++" layer of Android to access.
Re:Bare-metal Rust in Android by okanat on Monday October 09, 2023 @08:48PM (#37827330)
In theory it is possible to write raw Binder calls to various Android services, skipping JNI in many places. However, it is basically rewriting the entire OS API and structure from scratch.
Re:Bare-metal Rust in Android by defer on Monday October 09, 2023 @09:18PM (#37827524)
You can generate binder wrappers from aidl, that would work. This is fairly common when doing platform work (for those like me who work on the operating system rather than on apps).

However, this would be a terrible idea because usually the android api is stable at the Java wrappers (I.e. ActivityManager), not at the aidl level, which would make this very fragile for app development across a multitude of devices and platform versions.

Re:Bare-metal Rust in Android by izacus on Tuesday October 10, 2023 @02:46AM (#37829190)
Sure, and some NDK APIs do exactly that. But you're still just using IPC to call into services written in Java, just using a different approach.
Re:Bare-metal Rust in Android by kllrnohj on Monday October 09, 2023 @10:21PM (#37827888)
> Those "native" APIs you mention in most cases just call back to Java APIs under the hood

Some do, but most don't.

Re:Bare-metal Rust in Android by azemetre on Monday October 09, 2023 @03:08PM (#37824040)
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.

Re:Bare-metal Rust in Android by asrael_io on Monday October 09, 2023 @03:53PM (#37824674)
Not quite production, but I was on a paid contract on a PoC. I would say back at 1.0, mobile was pretty painful and signing of any binary dependencies was up to you. It looks like they addressed signing in 1.5 and I haven't picked it back up to check out the mobile experience.
Re:Bare-metal Rust in Android by flohofwoe on Monday October 09, 2023 @04:44PM (#37825271)
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 by wredue on Monday October 09, 2023 @02:50PM (#37823824)
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)

Re:Bare-metal Rust in Android by cogman10 on Monday October 09, 2023 @03:10PM (#37824062)
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 memory consumption. It's not exactly great for runtime performance as it takes away some key optimizations.

Another benefit of rust assuming you are distributing binaries is you'll be able to use the latest version of Rust rather than being pinned to older versions of the SDK with partial support based on the whims of google.

Re:Bare-metal Rust in Android by shopvaccer on Monday October 09, 2023 @03:20PM (#37824198)
>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. It's not exactly great for runtime performance as it takes away some key optimizations.

That is fair I suppose

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.

Re:Bare-metal Rust in Android by wiseowise on Monday October 09, 2023 @04:50PM (#37825329)
> 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.

Re:Bare-metal Rust in Android by galangalalgol on Monday October 09, 2023 @03:55PM (#37824702)
VM warmup isn't consistently a thing, in fact for over a decade there has been plenty of observation of the reverse, that runtime optimization often slows performance. Systems languages (c/c++/rust) consistently outperform warmed up managed languages. And that is ok, it doesn't mean we shouldn't have managed languages, but they are slower.
Re:Bare-metal Rust in Android by pjmlp on Monday October 09, 2023 @05:02PM (#37825443)
Managed languages also exist in AOT with PGO data.
Re:Bare-metal Rust in Android by flohofwoe on Monday October 09, 2023 @04:39PM (#37825220)
> 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 faster code than AOT compiled code, but in practice that usually turns out as wishful thinking.

Re:Bare-metal Rust in Android by pjmlp on Monday October 09, 2023 @05:01PM (#37825435)
Thankfully ART not only uses JIT, it also has an AOT compiler with PGO data shared across all devices in the ecosystem via the Play Store.

In practice, people should learn how Android actually works.

Re:Bare-metal Rust in Android by flohofwoe on Tuesday October 10, 2023 @07:19AM (#37830708)
This just seems to prove my point that AOT is usually better than JIT?
Re:Bare-metal Rust in Android by pjmlp on Tuesday October 10, 2023 @10:15AM (#37832400)
Not really, because not only it uses PGO, which most people using AOT languages never bother to learn, it only AOT compiles the code paths that JIT validated as being used, instead of the whole application.

JIT + AOT with PGO data shared across all Android devices on the planet, gets the best of both worlds.

Re:Bare-metal Rust in Android by rstat1 on Monday October 09, 2023 @03:08PM (#37824038)
Not having to use Java or any of its weird derivatives.
Re:Bare-metal Rust in Android by smith7018 on Monday October 09, 2023 @03:12PM (#37824085)
I implore you to try Kotlin; it’s a fantastic language and is a wonder to code in
Re:Bare-metal Rust in Android by rstat1 on Tuesday October 17, 2023 @05:27PM (#37921829)
Kotlin is what I meant by "weird derivatives"

But anyway I have used it. Didn't understand why it existed then. Still don't.

All these weird languages and UI frameworks where you write hundreds of lines of code just do simple UI layouts, no thanks.

Re:Bare-metal Rust in Android by Vt71fcAqt7 on Monday October 09, 2023 @03:09PM (#37824045)
You can already. The ndk allows any language to be compiled to android. For rust see

https://github.com/rust-mobile/ndk

Which has the tools to do this.

Re:Bare-metal Rust in Android by wiseowise on Monday October 09, 2023 @04:44PM (#37825266)
Why?
Re:Bare-metal Rust in Android by adastra22 on Monday October 09, 2023 @07:15PM (#37826652)
You can though? I maintain a rust-only app.
Re:Bare-metal Rust in Android by Thorrez on Monday October 09, 2023 @10:56PM (#37828060)
While not a bad idea, it doesn't have the urgency of C->Rust because Java is already memory safe.