[HN Gopher] Rust in the Android Platform
___________________________________________________________________
Rust in the Android Platform
Author : theafh
Score : 161 points
Date : 2021-04-06 17:08 UTC (5 hours ago)
(HTM) web link (security.googleblog.com)
(TXT) w3m dump (security.googleblog.com)
| domano wrote:
| Is Fuchsia (and Flutter by Extension) dead since the Oracle thing
| has worked out now?
| bluejekyll wrote:
| What, if anything, do these have to do with each other?
| [deleted]
| thesuperbigfrog wrote:
| >> For the past 18 months we have been adding Rust support to the
| Android Open Source Project, and we have a few early adopter
| projects that we will be sharing in the coming months. Scaling
| this to more of the OS is a multi-year project. Stay tuned, we
| will be posting more updates on this blog.
|
| 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.)
| stusmall wrote:
| If official* APIs come then they will probably come via ndk.
| It's been a while since I've heavily done Android dev but
| historically those APIs have lagged behind a lot. At one point
| there was a major push to catch them up but they were still
| pretty second class.
|
| I'd still much rather use the standard SDK and kotlin and I
| absolutely adore rust.
|
| *There are already unofficial ndk crates for rust.
| steveklabnik wrote:
| They say earlier
|
| > 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!
| larsberg wrote:
| That's exactly right. Today, the focus is on making it
| possible to use Rust to write pieces of the Android platform
| itself.
|
| 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.
| k__ wrote:
| Shouldn't Rust be able to hook into the NDK already anyways?
| david_allison wrote:
| Yep: https://github.com/mozilla/rust-android-gradle
| steveklabnik wrote:
| I haven't personally done it, but given Rust can call C and
| be called like C, I don't know why not. I do know that Rust
| is being used in Android apps like Cloudflare's 1.1.1.1
| app, but I don't know if those make ndk calls or not.
| souldeux wrote:
| I don't know enough about Kotlin to know if it's useful or not
| to point out Kotlin/Native: https://kotlinlang.org/docs/native-
| overview.html
| The_rationalist wrote:
| GraalVM native is generally better than Kotlin native as it
| maintain Java-kotlin interop. Kotlin native is more for niche
| use cases like objective-C/Swift interop.
| nindalf wrote:
| The third paragraph says
|
| > 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.
| jeroenhd wrote:
| There's already an API for native activities. While I doubt
| that Google will be the one to release the framework to write
| Rust applications, there's no reason why it would be
| impossible to interface app-level Rust with the Android SDK.
|
| 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.
| berkes wrote:
| While it feels terribly hacky, one could probably write an
| Android-wrapper around Rust in Java. A rather big
| undertaking, I'd guess, since it means exposing all APIs to
| rust somehow.
|
| 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".
| Argorak wrote:
| The biggest problem here is that in Android, Java "owns"
| the app, so you will have to invert a lot of lines to make
| "develop a whole app in Rust" feel awesome.
|
| 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
| raphlinus wrote:
| The "cargo apk" tool already exists to bundle Rust code
| into a NativeActivity that can be run without needing to
| write any additional Java code. The API surface so provided
| is more limited than the full toolkit, but could be useful
| in many domains. It's currently mostly used for games. I am
| using it for the Android port of piet-gpu, and it's working
| pretty well.
| username_my1 wrote:
| I think you can do 60fps on android with kotlin easily ... in
| fact you can do that with RN (if you're careful).
|
| 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 ...)
| scoopr wrote:
| The android new bluetooth stack rust rewrite was discussed
| recently[0]
|
| [0] https://news.ycombinator.com/item?id=26647981
| ed25519FUUU wrote:
| One of the good things about putting Rust in android is that it's
| a _great_ way to encourage AARCH64 support in the language.
| steveklabnik wrote:
| ARM themselves helped do the legwork here; aarch64-unknown-
| linux-gnu is already a Tier 1 supported platform thanks to
| their work https://doc.rust-lang.org/nightly/rustc/platform-
| support.htm...
|
| 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.
___________________________________________________________________
(page generated 2021-04-06 23:01 UTC)