News for hackers. Stuff that matters.
Re:Rust in the Android Platform by nindalf on Tuesday April 06, 2021 @03:45PM (#26716495)
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.

Re:Rust in the Android Platform by jeroenhd on Tuesday April 06, 2021 @04:28PM (#26716986)
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.

Re:Rust in the Android Platform by throwaway189262 on Tuesday April 06, 2021 @11:58PM (#26720442)
Java is a better fit for high level code, and you can already use Rust where performance matters.

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.

Re:Rust in the Android Platform by asveikau on Tuesday April 06, 2021 @09:16PM (#26719446)
I think another problem is that native binaries for multiple architectures would grow the binary, one per arch; aarch64 is not the only thing android runs on. Maybe some people would also forget that and not bother targeting others.
Re:Rust in the Android Platform by rbanffy on Tuesday April 06, 2021 @07:17PM (#26718553)
Honestly, between the magic Kotlin adds on top of Java and Rust, I prefer Rust. At least it’s not doing stuff behind my back.
Re:Rust in the Android Platform by bobthebuilders on Tuesday April 06, 2021 @07:42PM (#26718753)
C++ is better. Rust is a cargo cult language (same with Kotlin, Kotlin especially is a corporate language to sell more IDEs and Google was bribed by JetBraine to adopt it). Rust is just a bad attempt at reinventing the wheel.
Re:Rust in the Android Platform by howinteresting on Tuesday April 06, 2021 @09:32PM (#26719560)
Rust is a fantastic attempt at reinventing C++. It works really well. I've been writing production code in it for the last few years and it's an utter delight to use.

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.

Re:Rust in the Android Platform by carlhjerpe on Tuesday April 06, 2021 @09:50PM (#26719682)
Considering way less than 50% of developers are nonbinary/transgender, don't you get the impression that they're then trying to fill quotas rather than picking the best speakers? Not saying they weren't the best, just that either rust is a very unique community or something is "up" with the selection.

Just to clarify, I'm asking with good intent.

Re:Rust in the Android Platform by howinteresting on Tuesday April 06, 2021 @10:16PM (#26719857)
There's a selection effect: people like me experience so much ambient hostility in society that we gravitate towards communities that welcome us and that already have people like us in leadership positions. So the correct metric is not % of all developers as a whole but just the ones involved in the Rust community.

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.

Re:Rust in the Android Platform by carlhjerpe on Tuesday April 06, 2021 @10:48PM (#26720054)
I've been thinking about a good answer, but these days it's a fine line to talk about these things. I'm happy the rust community is so open while being widely successful. Might shine some light into the rest of the world. I'm from Sweden,where this kind of hostility probably exists, but I never see it (gay people are very well accepted, trans I'm not as certain, only have a pool of 1 friend so not enough data).
Re:Rust in the Android Platform by howinteresting on Wednesday April 07, 2021 @12:19PM (#26727083)
I'm not Swedish so I don't know much about what it's like to be a Swedish trans person.

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...

Re:Rust in the Android Platform by Rule35 on Thursday April 08, 2021 @08:14PM (#26745362)
I think the discussion gets a bit blurred around what acceptance means.

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.

Re:Rust in the Android Platform by dabraham1248 on Tuesday April 06, 2021 @10:27PM (#26719920)
It might be that people from disadvantaged communities _need_ to have more talent & insight to become experts than people like me (straight, white, male, speaks English, went to college, ...) and (I assume) you. And even more so to become _recognized_ experts. Also, they might feel more of a need to demonstrate that they should be allowed in the "club".

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.

Re:Rust in the Android Platform by carlhjerpe on Tuesday April 06, 2021 @10:50PM (#26720062)
Good insight, it seems like the reply below said the talks were submitted blindly though, so that's even better. They're just accepted and doing really well!
Re:Rust in the Android Platform by anoncake on Wednesday April 07, 2021 @03:38AM (#26721517)
Somehow, queer people are subconsciously attracted to each other (not necessarily in a romantic or sexual way). While 50% non-cis is surprising, when we are represented we tend to be overrepresented.
Re:Rust in the Android Platform by wffurr on Tuesday April 06, 2021 @09:10PM (#26719417)
Rust is a bad attempt at reinventing C++? That's a unique take.

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.

Re:Rust in the Android Platform by throwaway189262 on Wednesday April 07, 2021 @12:03AM (#26720468)
No way. Rust is great, trust me.

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.

Re:Rust in the Android Platform by lenkite on Wednesday April 07, 2021 @04:01AM (#26721686)
"Every feature you have in C++, Rust does it better"

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

Re:Rust in the Android Platform by pixel_fcker on Wednesday April 07, 2021 @05:27AM (#26722284)
Macros baby
Re:Rust in the Android Platform by lenkite on Wednesday April 07, 2021 @06:45AM (#26722973)
AFAIK, macros are only applicable to a subset of problems. Anyways, I found that variadic generics is a draft RFC: https://github.com/rust-lang/rfcs/issues/376
Re:Rust in the Android Platform by scoutt on Wednesday April 07, 2021 @10:27AM (#26725437)
>Every feature you have in C++, Rust does it better.

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.

Re:Rust in the Android Platform by 3836293648 on Wednesday April 07, 2021 @12:10PM (#26726959)
How is calling drop any different from calling close?
Re:Rust in the Android Platform by scoutt on Wednesday April 07, 2021 @01:34PM (#26728097)
For the practical case is not different. But is not coherent. It’s weird. And opening/closing files is an historical concept.

Why “drop” is the opposite of “open”? Let’s change “open” for “lift” or “notdrop”.

Re:Rust in the Android Platform by nl on Wednesday April 07, 2021 @03:11AM (#26721358)
Google was bribed by JetBraine to adopt it

It's hard not being sarcastic in reply to this. But no, this did not happen.

Re:Rust in the Android Platform by berkes on Tuesday April 06, 2021 @03:54PM (#26716607)
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".

Re:Rust in the Android Platform by raphlinus on Tuesday April 06, 2021 @04:16PM (#26716839)
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.
Re:Rust in the Android Platform by Argorak on Tuesday April 06, 2021 @04:07PM (#26716741)
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

Re:Rust in the Android Platform by berkes on Wednesday April 07, 2021 @04:44AM (#26721982)
> But, TBH, I think Kotlin and Java

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.

Re:Rust in the Android Platform by Argorak on Wednesday April 07, 2021 @05:46AM (#26722495)
Well, this is always a tradeoff: the cost of being away from the mainstream may outweigh familiarity with a programming language at some point.

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.

Re:Rust in the Android Platform by skybrian on Wednesday April 07, 2021 @01:54AM (#26720997)
Apparently the Android team is still not recommending Flutter. Hmm.
Re:Rust in the Android Platform by pjmlp on Wednesday April 07, 2021 @03:14AM (#26721375)
Why should they? Jetpack Compose is their defensive answer against Flutter.