3

In Android OS, I am able to run several Java JAR files compiled under desktop environment. For instance, jtransforms

May I know why is it so? I thought the JVM from Oracle and Dalvik VM from Google uses two different byte code formats? Why the JAR file compiled by Java SE able to execute in Android?

3 Answers 3

6

I assume you are simply including the jar file in your android project? Then it works, as during the build process it is converted (the same is done for your own class files!) to dex format. This is done with the dex (dx) tool. Using ADT in eclipse it is automatically done for you. It's available for manual use in the android sdk of course too:

Under android-sdk-windows\platform-tools\dx.bat if on windows.

1

According to wikipedia, dx is used to convert compiled .class files into the .dex format.

2
  • What does a JIT compiler have to do with this? That is for the virtual machine, not the compiler. Jun 17, 2012 at 11:53
  • I thought that would allow this to happen at runtime, but maybe that's not true so I'll remove it for now. Jun 17, 2012 at 11:54
0

1. Java SE - Java (Swing + AWT) = Android

2.In 2005, when Java was undergoing changes, Android creator didnt wanted to base Android totally on Java. So they included JVM as the 1st compilation unit, thats the reason JRuby , Jython, etc can be used to write Android apps. And 2nd Compilation unit as Dalvik Compiler.

3. So its quite natural that a jar file compiled under desktop environment works fine on Android.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.