.dex貌似只是压缩了.class。都是一样的

解决方案 »

  1.   

    dex只是打了一个包,在sdk中有做解释,请参考。Opens a DEX file from a given File object. This will usually be a ZIP/JAR file with a "classes.dex" inside. The VM will generate the name of the coresponding file in /data/dalvik-cache and open it, possibly creating or updating it first if system permissions allow. Don't pass in the name of a file in /data/dalvik-cache, as the named file is expected to be in its original (pre-dexopt) state.
      

  2.   

    如果是这样的话,那为什么说Android的VM和标准JVM不兼容,不能运行标准的Java字节码那??另外,是否是可以这样理解:Android里的 .class 和标准Java中的 .class完全一样。 只是Android中的Application,必须将 .class 打包成 .dex, 然后再打包到APK中。  但是, 对于Android中的库什么的, 完全可以直接使用 .class, 且可以打包成jar, 这里的jar和标准java中的jar格式也完全一致吗?比较不解究竟Android中的Java字节码和标准Java的区别在哪里,何时有区别谢谢~~~~~
      

  3.   

    总之,我想知道的是所有的文档上都说 Android用的是 dalvik虚拟机,和标准的JVM不兼容,所以,不能执行标准的Java字节码,只能执行经过转换后的dex格式。OK, Android的Application发布时为APK格式,APK中确实包含了经过class文件转换后的classes.dex但是,Android平台的Framework,System中的大量的库文件,都是jar文件,解压后可以看到还是标准的java字节码格式,即 .class文件。  这不是自相矛盾了吗? 怎么Android应用用的dex格式,而Android库还是class格式那??
      

  4.   

    google对dex的描述,其应用主要是对ap的优化。The directory that holds the optimized form of the files is specified explicitly. This can be used to execute code not installed as part of an application. The best place to put the optimized DEX files is in app-specific storage, so that removal of the app will automatically remove the optimized DEX files. If other storage is used (e.g. /sdcard), the app may not have an opportunity to remove them. 
      

  5.   

    现在很多文档中都只提到了application发布的过程中,由DX工具将class文件转换为dex,然后再打包成apk。但是,android平台本身使用的很多库,还是jar格式的,不解~~~
      

  6.   

    To yyy025025025:你的意思是,Android的dalvik虚拟机同时支持运行标准的Java字节码(class文件)和Dex格式(dex文件)??只是对于Application,APK中包含的必须是dex格式?? 其他的场合下(比如系统库,扩展库等),还是允许使用class文件(Jar)的???
      

  7.   

    dex是一种优化的方式,在运行前需要将dex文件中代码,解压到dalvik-cache中,然后dalvik启动cache中的class。dex对jar文件做的优化,主要是将其的依赖关系写到dex文件中,而不需要在运行时动态的计算。但是对于依赖关系复杂的class,这种优化反而会降低效率。This means that splitting code out into many separate DEX files has a
    disadvantage: virtual method calls and instance field lookups between
    non-boot DEX files can't be optimized.所以google建议打包成dex的文件,是单一的,并且在更新它的时候,不需要对其他文件重新进行dex的打包动作。那么符合这些条件,就是application程序。
    另外android最终还是运行jvm,还是使用.class去load进jvm中,只不过是对jvm的初始化做了优化。
      

  8.   

    非常感谢yyy025025025。 我加你为好友了,是否是需要你的同意? 另外,我还是有一不解, 那按这样说的话,DEX仅仅是一种优化方式,也就是说是可选的。 那可选的东西,谁都可以发布时转成dex,也可以不转,这样岂不是造成混乱??  还是Google有强制的规范和运行时机制,来限制谁必须使用dex优化,谁必须不使用, 比如application打包时,必须转成dex, 其他的必须使用原始class,不能转成dex??