Search code examples
androidcross-compilingdalvik

a compiler that compiles down to dalvik bytecode?


So i have been trying to understand how android works and from what i have gathered so far:

-It seems that the only way to write an android app is by using java

-Apps run in a virtual machine called the "dalvik virtual machine"

-The way java files get compiled to dalvik bytecode, which can run on the virtual machine, is by first compiling it with the java compiler to get java bytecode and then using a compiler, provided by android, to "translate" the java bytecode to dalvik bytecode.

My questions is, if that's all there is to it
then wouldn't it be possible to create a C/C++ (or any other compiled language for that matter) compiler that can compile down to dalvik bytecode?

i mean, we already have cross platform compilers for c++ that support various cpu architectures, why dont they make them support the dalvik "architecture" as well?


Solution

  • It seems that the only way to write an android app is by using java

    You are welcome to use C/C++ as well.

    Apps run in a virtual machine called the "dalvik virtual machine"

    Only on Android 4.4 and older. Newer devices use a new runtime environment called ART.

    then wouldn't it be possible to create a C/C++ (or any other compiled language for that matter) compiler that can compile down to dalvik bytecode?

    Can you craft other languages that compile to Dalvik bytecode? Sure. Can you compile some existing language to Dalvik bytecode? Only if the language features of that language can be implemented (reasonably) in Dalvik bytecode.