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