Why is it, that android apps are required to run inside a VM(dalvik/art)?

223 views

is this OS level restriction?

if so why did android decide to go this route? also why java? c# is also platform independent

​

another stupid question if there were a jvm implementation like dalvik or ART on iOS would the programme compiled for android run-on iOS?

if so, can anybody create said implementation or can it only be provided by apple?

In: 0

3 Answers

Anonymous 0 Comments

Yes, it is a security restriction. Desktop is also moving towards offering a similar system with Windows Store applications and Ubuntu Snap Store, both of which severely restrict access to the system with a permissions based approach.

Android went this route because the no. 1 reason for virus infections is the user downloading some sus program that then has access to most of the system because it runs with the security access of the user. The vast majority of mobile applications don’t need access to anything other than maybe the photos folder, so why give them the keys to the house? Note that a phone is basically the perfect spy bug, with GPS, multiple cameras, microphones, even an NFC reader to skim credit cards that brush against it in your pocket. It is imperative to restrict access to the systems.

Why java instead of C#? Because C# was not open source until 2016 and it was *very* platform dependent. The only cross platform C# runtime at the time android was being developed was mono, which while being very impressive and the basis of crossplatform Unity games, had many drawbacks and is still behind on implementing language features. Java was made to be crossplatform from the start, and Google had tons of java developers.

Anonymous 0 Comments

> is this OS level restriction?

It’s the way Android is designed, it’s not a “restriction” really it’s just how it works.

> if so why did android decide to go this route?

Hardware compatibility. If you run everything in a VM, then you can always target that VM with your code, regardless of what the underlying hardware is. As long as it’s running the interpreter your code will work. This is the entire point of java, “write once, run anywhere”

> also why java?

It’s just the choice they made, probably because at the time java was the more popular programming language and so access to java developers was easier, and java was designed from the ground up to be hardware independent which is a pretty big deal if you are outsourcing your hardware to independent manufacturers.

> another stupid question if there were a jvm implementation like dalvik or ART on iOS would the programme compiled for android run-on iOS?

It would run on the VM inside iOS, so it wouldn’t really be running on iOS.

Anonymous 0 Comments

The premise of your question is not entirely accurate. Android allows you to write parts of application in C and C++. Native code runs outside of the VM but inside the security sandbox. Google could provide a full C/C++ SDK but they clearly wanted and still want to keep majority of Android apps architecture-independent.

Google said availability of 3rd party libraries in java around the time Android was designed was the motivation to use java.

You can implement an Android compatible virtual machine on iOS but you can’t implement all Android APIs without Apple support.