17

More concretely, I'm asking this: why aren't applications compiled fully to native code before distribution rather than bytecode that runs on some virtual machine or runtime environment?

Implementation details aside, fundamentally, an Android application consists of bytecode, static resources, etc. In the Java world, I understand that the main appeal of having the JVM is to allow for enhanced portability and maybe also improved security. I know Android uses ART, but it remains that the applications are composed of processor-independent bytecode that leads to all this complex design to convert it into runnable code in some efficient manner. See: ART optimizing profiles, JIT compilation, JIT/AOT Hybrid Compilation... that's a lot of work to support this complex design.

Android only officially supports arm64 currently, so why the extra complexity? Is this a vestigial remnant of the past? If so, with the move up in minimum supported versions, I should think Android should be transitioning to a binary distribution model at a natural point where compatibility is breaking. What benefit is being realized from all this runtime complexity?

top 7 comments
sorted by: hot top controversial new old
[-] MajesticNubbin@lemmy.world 18 points 1 year ago

The Androids book by Chet Haase provides a good look at the early history and design decisions of the platform and how they came to be made.

At the time there was a debate inside the team over what language their app development framework should use, with native C++ and Java being the two main options (I think there might have been another option or two, I can't recall). In the end Java won out, and from memory one of the main reasons was to make it easier to make apps and not need to think about the lower level parts of the platform, i.e. the platform takes on the complexity internally in order to lower the barrier to entry for app developers. The idea being that a lower barrier to entry would result in more apps being developed for the platform. For a brand new platform that lives and dies by the apps available for it, that's a pretty sensible trade-off.

And yes, Android has a lot of vestigial remnants of the past, the Android framework team has been very particular about maintaining as much backwards compatibility as possible within the framework.

[-] minorninth@lemmy.world 10 points 1 year ago

First of all, since the very early days Android has always allowed apps to make use of native code using the "NDK", and in fact most games and most apps that do any sort of AI, image processing, or anything else complex like that make heavy use of native code already, for performance reasons.

Keep in mind that the decision to base Android apps around Java was made back in 2003 when Android was founded. Some of the reasons they picked Java were:

  • It's one of the most widely known languages by developers
  • It's hard to write code in languages like C and C++ without introducing memory bugs and security bugs. Using a higher-level language makes those bugs far less common.
  • It's portable - you note that Android only supports arm64 now, but at the time it was arm32, and Android has actually always had some level of support for x86 - you can run the emulator for x86, and some x86 Android devices exist. Using a bytecode language means Android is future-proof
  • It's not limited to just Java - the JVM has a rich ecosystem of languages that developers can use

Now 20 years later I think it's worked out pretty well. It's hard to imagine picking a different language would have worked out better. Java is still just as popular as ever, and Android developers can take advantage of all of the Java tools from any other platform or application.

Apple's original option for iOS apps was just Objective-C, which is higher-performance, but overall it's a more obscure, difficult to use language. Developers adopted it despite Obj-C, not because of it. Apple had to invent Swift to provide a more modern alternative, because Obj-C is basically not used anywhere else and it felt very ancient. While Swift is a pretty great language, it's still somewhat obscure, only used for iOS and Mac apps - while Java and JVM languages are used everywhere.

Anyway, let's say that Android really did want to switch, for some reason. I'm not sure why you think switching to compiled code would be less complex. How would all of the millions of existing Android apps migrate? What native languages would be supported? It'd be a huge transition for dubious benefits.

As it is, Android is extremely flexible. While the official APIs require a JVM language, because of the NDK you can basically write Android apps in whatever language you want. People have built frameworks enabling you to build Android apps in nearly every language under the sun.

[-] outofband2@lemmy.world 1 points 1 year ago

Thank you for this great and detailed answer!

I would also add that today JVM environments support more languages such as Scala, Kotlin, and Clojure (to name a few). So more variety and more modern paradigms are available.

As for native languages, we are more or less left with C, C++, Go and Rust. Also some of them are really awesome, none seem like a good choice for general-purpose app development.

And a counter-intuitive thing is that modern run times are so well optimized that sometimes they can outperform native applications (I'm not talking about very tight calculations such image processing and AI), because JIT has much more information about both the specific hardware and run time introspection that is unavailable at compile time.

[-] AI_toothbrush@lemmy.zip 0 points 1 year ago* (last edited 1 year ago)

Yeah but at the same time if you support c++ for example its still extremely relevant language(i like c better tho...) and you could build support onto that stable base instead of using the $hitstorm called java. Well thats my opinion anyways. Maybe ease of use is more important and making phones that are powerfull enough to be used as a laptop is the right path forward. But making android more efficient would take a lot of other things and im not nearly qualified enough for this discussion.

[-] aluminium@lemmy.world 1 points 1 year ago

I think there are a couple of things to consider. Number one is that Android at the very beginning never was designed for large touchscreen phones, rather it was supposed to be a small portable Software Stack that would run on digital cameras where Java would be good enough.

Another historic thing that must have played into this is that Android was fighting an uphill battle. At the time iOS, PalmOS, BlackberryOS, Symbian and Windows Mobile all were shipping units. So I think they knew they had to keep the barrier of entry for creating Apps as low as possible and Java was (and still is) an incredible easy to understand language with a very gentle learning curve. Plus it was one of the most widley used language with robust tooling.

Also for implementation - Android actually was AOT compiling Apps during installation during the Android 5 and 6 days however starting with 7 they went away from that by using a hybrid approach. Basically if you download an App and launch it the first time, it would run in JIT mode and collect data and than compile and optimize cirtical parts while the phone is idle and charging. There even is an adb command (adb shell cmd package compile -m speed -f my-package) to manually compile apps. But I have played around with this a lot, trust me, and I can't notice a difference.

Also more generally I think that Android Apps being mostly made up of intermediate bytecode instead of raw CPU instructions is overall a massive benefit for security and incredible futureproofing. It allows for things like x64 Chromebooks and Asus Zenfones with Intel Atom SoCs (yes that was a thing) and would make a transition to a new ISA like RiscV somewhat managable I think. Also I don't think Java and its performance overhead matters - usually its badly coded Apps or these god awful wrapped webview "apps" that cause issues. Simple as that. If you today compare a Nexus 5 and an iPhone 5S, the Nexus 5 is faster 8/10 times, and that despite having a slower CPU and the whole java stack.

load more comments
view more: next ›
this post was submitted on 02 Jul 2023
17 points (94.7% liked)

Android

28063 readers
164 users here now

DROID DOES

Welcome to the droidymcdroidface-iest, Lemmyest (Lemmiest), test, bestest, phoniest, pluckiest, snarkiest, and spiciest Android community on Lemmy (Do not respond)! Here you can participate in amazing discussions and events relating to all things Android.

The rules for posting and commenting, besides the rules defined here for lemmy.world, are as follows:

Rules


1. All posts must be relevant to Android devices/operating system.


2. Posts cannot be illegal or NSFW material.


3. No spam, self promotion, or upvote farming. Sources engaging in these behavior will be added to the Blacklist.


4. Non-whitelisted bots will be banned.


5. Engage respectfully: Harassment, flamebaiting, bad faith engagement, or agenda posting will result in your posts being removed. Excessive violations will result in temporary or permanent ban, depending on severity.


6. Memes are not allowed to be posts, but are allowed in the comments.


7. Posts from clickbait sources are heavily discouraged. Please de-clickbait titles if it needs to be submitted.


8. Submission statements of any length composed of your own thoughts inside the post text field are mandatory for any microblog posts, and are optional but recommended for article/image/video posts.


Community Resources:


We are Android girls*,

In our Lemmy.world.

The back is plastic,

It's fantastic.

*Well, not just girls: people of all gender identities are welcomed here.


Our Partner Communities:

!android@lemmy.ml


founded 2 years ago
MODERATORS