views:

915

answers:

5

Android is based on Linux; can native Linux applications be run on Android?

+8  A: 

In general, no. Android apps run in a sandboxed Java-like virtual machine, so have to be written in Java or some language that compiles to virtual-machine bytecode.

However, the virtual machine does run on top of the underlying Linux OS, and there are ways to call native code. See http://developer.android.com/sdk/ndk/1.6_r1/index.html

Kristopher Johnson
That's a rather indirect answer. Yes, Android can run Java apps, since it's a Linux distribution that comes with a JVM. But that JVM is obviously a native application itself, so there is at least one native Linux application that can run on Android/Linux.
MSalters
Actually, Android doesn't come with a JVM, it comes with a Dalvik VM. The Dalvik VM comes with a Java language implementation that compiles down to Dalvik bytecode, but not to JVM bytecode. I believe there's also a tool that can convert compile JVM bytecode into dalvik bytecode. Wikipedia (as usual) has a pretty good introduction to Dalvik: http://en.wikipedia.org/wiki/Dalvik_virtual_machine
Bob McCormick
I don't think it's an "indirect answer." I understand the question to mean "Can a typical user install native Linux applications on Android." I think the answer to that is No, but obviously, as Android runs on top of Linux, there are native Linux programs running.
Kristopher Johnson
+5  A: 

Android does not run X Windows, nor does it have many of the standard GNU libraries. So, since most native linux applications require one or both of these, most will not run.

In addition, even Java programs can be limited, because the version of Java that Android applications are written in is a subset of the standard Java library.

ZacharyP
+4  A: 

Not directly, no. Android's C runtime library, bionic, is not binary compatible with the GNU libc, which most Linux distributions use.

You can always try to recompile your binaries for Android and pray.

jcorbier
A: 

Yes they can if they're compiled under an arm linux first or using a cross compiler. Debian arm versatile works, there's also arm-eabi for compiling under x86 linux to arm linux.

Will
+1  A: 

You can get an ARM cross compiler that runs on Linux here. You can also download the Android NDK and compile some command line apps. I do not have any personal experience with using C++ with either solution, but I have compiled a few simple things with both. It is my understanding that the NDK is not a full C++ compiler as there have been complaints that it will not compile some common C++ code.

Note that since I am a new user, I cannot post the NDK link... :/

JimR
Here's a link to the NDK, here's hoping it is allowed: http://developer.android.com/sdk/ndk/index.html
JimR