Rust in the Android Platform
security.googleblog.com
security.googleblog.com
Patiently waiting for the Rust APIs to arrive . . .
Java feels so heavy, so getting to use Rust would be a breath of fresh air.
(Kotlin has been better, but it also requires the JVM.)
> now supports the Rust programming language for developing the OS itself.
So, this seems to be about in Android, not building apps for Android.
Guess we'll see with more posts!
Certainly, there are some _apps_ on Android today that use Rust (shout-out to my Firefox friends!), but that's not something I'm investing in right now.
I expect replacing low-level C++ with Rust to result in improved platform reliability as well as reduced security bugs.
For every weird memory safety bug that is usefully exploitable there are a hundred more that just mysteriously break things and may be very difficult for a human to spot. My WebAuthn tests broke on my Pixel 2 on Saturday, I spent about an hour trying to debug the problem, wondering why it was happening now but not before and why it didn't affect other platforms - then I rebooted the phone and it went from reporting a "NotReadableError" about the secure local storage to just working.
> Managed languages like Java and Kotlin are the best option for Android app development. These languages are designed for ease of use, portability, and safety.
You're not going to write Android Activities in Rust. Nothing is stopping you from adding Rust code to your Java/Kotlin app though.
An other approach would be to employ one of many thin webview wrappers, in which your app is HTML+Js+CSS. When such a webview wrapper supports WASM, the JS part could be written in rust.
Not something I'd do other than "to prove it can be done".
But, TBH, I think Kotlin and Java are _indeed_ fine application languages.
What Rust is already quite often used for is for libraries that work on both iOS and Android. For a public example, see the Glean SDK: https://mozilla.github.io/glean/book/index.html
I agree wholeheartedly.
But there will be a demographic of people who know Rust and not Java, but who might want to build an app. Somewhat similar to how there is an apparent need for "HTML+JS+CSS"-devs to build native apps.
I'm not sure if the argument for "HTML+JS+CSS" is purely familiarity, there's also technical arguments like portability and future-compatibility. But I _do_ hope that the portability story will become better in the coming years beyond just this stack.
The big problem with such a setup, of course, is that the application itself would be running inside a JVM/Dalvik VM, so the app would constantly be switching between Java and native, which can't be great for performance. However, it can be done; thankfully, Chrome and Firefox aren't completely compiled to byte code, the JIT and rendering code is written in native code. With Mozilla's use of Rust in their browser, that means that there's already a significant Rust runtime running on Android, at least.
If the app uses Rust and a library to hook the draw call, it should be fairly easy to write the app like a video game and render everything in Rust. This would come bundled with a tonne of accessibility problems, of course, as every rendered control would be a non-standard one.
I've put a lot of time into learning Rust and I still reach for Java for high level stuff. GC is just wonderful for developer productivity. Lifetimes are way better than C but still a PITA.
Especially when you mix with threading, you end up using Reference Counting anyways which is just shitty GC.
Memory safety is a big deal for writing secure programs, which has been repeatedly shown to be impossible to do at scale in C++. Provably safe parallelism and concurrency is key for performance on multi core devices, also extremely difficult to do safely and correctly in C++.
If C++ is the wheel being reinvented, it's not much of a wheel.
I maybe break out rust-gdb once a year. My code has fewer bugs than ever, thanks to extensive use of the high-quality modeling tools (types and lifetimes) provided by the language. My main project for the last year has had a grand total of one logic bug that was caught after release.
It also has an inclusive community: at the last RustConf, half the speakers were nonbinary and/or transgender. I fit both those criteria and feel more welcome in the Rust community than in that of any other language, meaning that I can do my best work in Rust.
Just to clarify, I'm asking with good intent.
The Rust community has many nonbinary and transgender people in it, and speakers are selected from the community. The selection process for RustConf is blind so the talks were picked for their merit: it just so happened that half of the speakers weren't cis.
> rust is a very unique community
Yes, this is true in my experience.
One thing I will say is that my general impression from afar is that Europeans are generally a lot more tolerant of the state interfering in personal identity issues than the liberal parts of the US. Iceland used to have a fixed list of approved baby names for example, something unimaginable in the US.
The situation was made better in 2019: https://www.icelandreview.com/news/icelandic-names-will-no-l...
It varies from acceptance of an adult just being trans, of trans babies, of schools preaching medical transition without parent approval, and of issue of bathroom usage and sex-segregated prisons.
Regardless of the political questions presumably Swedes are fairly liberal about someone's personal choices.
Put another way and exaggerated wildly for hopeful clarity, if person A became an expert despite being shoved away, and person B was wooed into the group, had tutors, friends,... I'd be more interested in A's talk than B's.
I'm not even going to say why because it would be a huge rant. It improves on C++ in virtually every way. Every feature you have in C++, Rust does it better. Every feature you wish C++ had, Rust has it.
I agree with you on Kotlin. It's better than Java on paper, but in much the same ways Groovy already was. And the advantages are shrinking in new versions of Java, especially if you use Lombok.
How does one perform generic fold expressions in Rust lang ? (Possible in C++ 17 and above)
https://foonathan.net/2020/05/fold-tricks/ https://en.cppreference.com/w/cpp/language/fold
IDK. I miss variadic functions (not macros) and being able to do certain simple things without resorting to strange paradigms, like arbitrarily closing an std::fs::File without needing to go out of scope or calling drop. Things like that.
Why “drop” is the opposite of “open”? Let’s change “open” for “lift” or “notdrop”.
It's hard not being sarcastic in reply to this. But no, this did not happen.
I'd still much rather use the standard SDK and kotlin and I absolutely adore rust.
*There are already unofficial ndk crates for rust.
Rust is not a UI programming language and shouldn't be.
but writing your own native modules in rust might be fun (VR, Audio processing, AI ...)
Rust seems like an excellent contender for the future.
If you have enough threads passing stuff around and can deal with the ~50% performance loss between Java and Rust, it's much easier to use a language with GC.
There's talk of adding a quality GC to rust and dedicated GC types. If/when that happens, Rust will be a contender for a bunch of higher level systems
UIs tend to have designs that require graph based structures and self referencial references, so in the end you get either lots of Rc<RefCell<>> and clone() calls, or have to bind the whole stack to fit into Rust's memory model.
Have a look at,
https://raphlinus.github.io/rust/druid/2019/10/31/rust-2020....
https://raphlinus.github.io/rust/druid/2020/09/28/rust-2021....
This is actually an area where iOS is more flexible. Because UIKit is C-accessible, it’s feasible to develop bindings to it for other languages, and even autogenerate them. It’s too bad the same isn’t true of Android Framework.
Google is planning to fix this eventually.
Android's API is also atrocious.
I hope this doesn't increment build time, otherwise it'll be a true pain.
>For complex C/C++ code bases, often there are only a handful of people capable of developing and reviewing the fix
I don't see why the Rust alternative would make solving bugs easier. It's ugly and hard to read, hard to parse and hard to follow (IMHO). If before there was "only a handful of people capable", now it will be less.
I could say the same about C++, it usually comes down to what you learned first.
But I disagree about less people being capable of writing it. I don't have any stats to back this up but for developers new to systems programming, Rust is more approachable than C++. The compiler does much more work in ensuring you don't screw up.
I've read accounts of Rust used in mobile along with Flutter UI. Not sure how successful that work has been.
Just because nowadays even MCU's are so powerful that you can just waste an insane amount of resources on TamaGo and just because TamaGo seems to run on custom hardware/firmware that specifically provides it what it needs to directly run on the hardware without help from C/C++/Rust, doesn't mean Go is particularly viable for Android today.
Even more importantly. Google actually wants to use a safe language for Android. Go isn't safe the moment you go parallel/concurrent/async. Go also isn't memory safe for important OS tasks like direct memory access. Go also isn't null safe. Go also isn't typestate safe... Rust have all of the above mentioned safety in all of the above mentioned situations.
- Direct memory access requires unsafe.
- Rust is also not null safe, unless you validate all unsafe code blocks
- Rust is also not typestate safe, unless explicitly programmed that way
As for GC being or not acceptable on kernel, plenty of worksation OSes have proven it works, only politics have hindered their further development.
Go was just the example at hand, I would have used D or any other better prepared GC systems programming language.
And then there are those bare metal JVM and Erlang runtimes deployed into production, even in matters of life and death like weapon control systems in battleships and missile tracking radars.
> Some people have imagined that Fuchsia's destiny is to replace Android, and some of them believe that's because Android is tainted by Java and Google will want to sidestep.
Whether or not Fuchsia can or might run Java or Kotlin apps, as you talk about, is not what this scenario is about. The apocalyptic scenario some believed about Fuchsia was that it existed as an OS that didn't need Java. If it can host & run Java or Kotlin apps? That might have had to go, that might have had to be cut. But Fuchsia could have survived.
Fuchsia is independent of Java and Kotlin. To run a Zircon kernel, to run a Fuchsia OS required no Java technologies. One maybe could/can use Java to write apps (having trouble stablishing this premise), but Java is not a dependency for this OS. With Fuchsia, Google could have given up Java, if they had to. What you @CameronNemo are talking about- the ability to use Java and Kotlin to write Fuchia apps, if true[1], is something that could have been sacrificed without affecting the rest of Fuchsia. I'd also point out that Fuchsia does not advertise Java or Kotlin support[2], regardless of whatever you may have heard, but it was at least once rumored of, so I can sympathize.
This is 99.9998% a conspiracy theory & in my estimation you'd have to be daft to think Fuchsia was only an escape hatch (there's a ton of great technical work breaking from Linux & more in it), but the "Fuchsia is only to escape Java if we have to" scenario sketched was at least technically plausible & sound, checked out. It has no Java dependencies.
[1] https://9to5google.com/2018/11/09/fuchsia-friday-java-borrow...
And the backwards compatibility. One of the codebases I work on has loads of untouched 15 year old code that runs fine on Java 16. Good luck doing that in JS, Python, or really any other popular language besides C/C++
far far more so, leaping to javas defense doesn't feel related to what this thread has been about. the thread has been about strategy & tactics, about escaping with something if the legal situation did go bad.
and as I stated, it doesn't seem like Google's Fuchsia does support Java. it might have been an idle notion, a legacy Android compatibility layer, but Java does not seem to be part of the modern Fuchsia attempt. at all. from what I can find. whatever pluses Java has, it doesn't seem like it's relevant enough to warrant any modern Fuchsia support. and the legacy Android support seems dubious / maybe non existent.
again I think the "fuchsia was just an escape hatch if Google had to have a non java based os" folks are a bit whack. but it was also a legit thread. even post Oracle trial, a break from 15 years of legacy & an underlying >2x as old posix api, for a more security conscious premise, sounds great, long long overdue.
Java has upsides but I don't think this thread should have to suffer that radical change in discussion. it muddies what was being talked about.
Fuscia and Java are both Android and tech related, don't see the problem. And the previous comment about Fuscia is just as off topic as mine, if not moreso. Java is at the core of Android and Fuscia hasn't made it out of the lab
We've explained again and again and again how the theory present is that Google needed an escape hatch from Java. The crude theory of Fuchsia being an escape hatch for Google, a way to get off Java, is at least true, in that it would help them get off Java. Which their most successful OS, Android, is extremely reliant upon.
Yes, underneath, Android uses Linux. Until recently it's been a fairly mangled, hacked up Linux, but allegedly Android keeps getting closer to being able to run on mainline Linux. But Android is not Linux. Android is Linux plus lots and lots and lots of subsystems: display & audio subsystems, all sorts of other stuff, endless apis & platform & device subsystems. A huge amount of them being written in Java. Google's #1 OS was extremely coupled to Java. This is in no way debateable? Spend a couple minutes doing the most cursory of investigations & you should see: Google was extremely tied to Java. Still are.
The sass is not appreciated. This entire thread has been quite frustrating. I feel like we are arguing past each other. I don't think this is a useful use of my time.
I think it has been useful. I'm sorry you are still unmoved. The situation seems clear to me, and quite heavily elaborated. I still don't see what your points are. There seems to be a fixation on Fuchsia as only a low level thing, but that's just Zircon, the smallest piece; Flutter & IPC & other subsystems make up a very different higher level system that is clearly attempting to be a new native app stack owned entirely by Google with licensing they control.
Just like they have been porting Android Runtime to Fuchsia during the last couple of years.
Also this never made sense, if Google really wanted to go down that path, they could have already replaced Android with ChromeOS for quite some time now.
ChromeOS is only partly their platform. They don't really maintain control over it. Because, like the iphone 1, it's web. It's a shared platform.
Also, why just escape Java when you can escape the GPL Linux kernel too!! Bonus!
Fuchsia OS really is an existential hedge, a fallback position unlike all else. I still am willing to guess though that it was argued & sold on it's technics. If anything, allowing good engineers a great attractive project: that's what it takes to attract & retain talent in the competitive tech world, giving some of your engineers really wild greenfield chances. Ideally in a highly visible manner. But a capabilities based OS free from Java, free from GPL: it's a good corporate-safe technically-strong starting point to "organize the world's information, make it accessible and useful" (yet secure).
Besides ChromeOS has its own specific APIs as well anyway.
Google's actual workaround to Oracle's lawsuit was to use OpenJDK, which also massively improved their Java compatibility. OpenJDK is produced by Oracle and under GPL, so using it (or just relicensing Apache Harmony as GPL) cuts off the API copyright claims (as you now have a license).
But it is true that there are other aarch64-* triples that could move up (including aarch64-linux-android). Getting to Tier 1 is extremely hard due to the CI requirements.
There's also second order effects; the CI has to succeed on all tests on all platforms, which means that if your PR breaks on a platform you don't have expertise with, you need help, and we need to be prepared to give that help to you in a timely manner. Again, probably easier on Android, but a general barrier.