3

在 Android 操作系统中,我能够运行在桌面环境下编译的多个 Java JAR 文件。例如,jtransforms

我可以知道为什么会这样吗?我认为 Oracle 的 JVM 和 Google 的 Dalvik VM 使用两种不同的字节码格式?为什么 Java SE 编译的 JAR 文件可以在 Android 中执行?

4

3 回答 3

6

我假设您只是将 jar 文件包含在您的 android 项目中?然后它就可以工作了,因为在构建过程中它被转换(对你自己的类文件也是如此!)到 dex 格式。这是使用 dex (dx) 工具完成的。在 Eclipse 中使用 ADT 会自动为您完成。当然也可以在 android sdk 中手动使用:

android-sdk-windows\platform-tools\dx.bat如果在 windows下。

于 2012-06-17T11:52:25.753 回答
1

根据维基百科,dx用于将编译后.class的文件转换为.dex格式。

于 2012-06-17T11:52:16.937 回答
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.

于 2012-06-17T12:31:03.663 回答