Reputation: 21
I'm looking to build a new app written in Java, can I write one code that can be executed both on an OS running Linux and OS running android? Or do I need to write two different codes one for each system?
Upvotes: 0
Views: 552
Reputation: 1361
Theoretically yes.
Android apps run in a Dalvik Virtual Machine, that comes with a Java language implementation that compiles down to Dalvik bytecode, but not to JVM bytecode. So, the code has to be written in Java or some language that compiles to Dalvik VM bytecode that uses the Android API.
However, the virtual machine runs on top of the underlying Linux OS, and there are ways to call native code. See NDK documentation.
So, it is technically possible to run native Linux programs on Android, as there is a Linux kernel running beneath everything.
Upvotes: 1