I read a lot about Dalvik and Google's Android OS when it first came out. One of the things that I don't quite understand though is why Java is used. The way I understand it is this:
Java code -> Java bytecode -> Dalvik bytecode
What I don't understand is why I have yet to see anything compile to straight Dalvik code or any other front end than Java for the Dalvik VM. Is there any work being done on a straight compiler or way to work with Android without Java?
To clarify I'm looking for languages that do not compile to Java bytecode. And also I'm not concerned with dynamic languages, I've read a few questions about them already. And also I'm aware of the NDK, I'm looking for information about Dalvik-compiled languages, not actual native-compiled langu开发者_如何转开发ages.
There is also a possiblity to write native Android applications running directly on the operating system (which is a variation of *nix). The recommended way for that is to use the Android NDK:
http://developer.android.com/sdk/ndk/index.html
There is also more "hacky" way to do that: use ARM C/C++ compiler and just write your applications like any ordinary *nix program. This fits mostly for background services without GUI, though.
What I don't understand is why I have yet to see anything compile to straight Dalvik code or any other front end than Java for the Dalvik VM.
The reason for this is basically that there is no need for a "direct-to-Dalvik" compiler, since, as you correctly point out, the existing compile chain goes via bytecode anyway.
The only reason to go directly to dalvik, would be if the language in some sense could take advantage of dex-features that's not in the bytecode. However, dex and java bytecode are extremely similar. Main difference is probably that Dalvik is register based while the JVM is stack based. Other than that, the instruction set is strikingly similar.
As you probably realized already, you can use any language that is based on the JVM, that is, that compiles to java bytecode.
Some examples:
- Scala on Android tutorial
- Clojure and Android with Emacs on Ubuntu
MonoDroid is a beta project that converts C#.NET code to Dalvik. It's not quite finished, but it will open some possibilities for people that know C#, but no Java.
Everyone uses Java because that's what Android development officially supports and it's what the Android SDK is based around developing in. However, they also offer the NDK (Native Development Kit) which allows you to develop in C/C++.
See their original announcement for it here: http://android-developers.blogspot.com/2009/06/introducing-android-15-ndk-release-1.html
精彩评论