Android 中的 .dex 文件是什么?
我对 dex 文件有一些疑问
- Android 中的
dex
文件是什么? - dex 在 Android 上如何工作?
- 如何使用它们来调试 Android 应用程序?
- 它们与java类文件相似吗?
我需要具体信息,请提供帮助,欢迎任何真实的例子!
I have some questions regarding dex files
- What is a
dex
file in Android? - How does dex work for Android?
- How are they used in debugging an Android app?
- Are they similar to java class files?
I need specific information please help on this and any real examples are welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于.dex文件:
Dalvik虚拟机
(Android系统下的主力)最显着的特点之一是它不使用Java字节码。相反,引入了一种名为 DEX 的本土格式,甚至字节码指令也与 Java 字节码指令不同。编译的 Android 应用程序代码文件
Android 程序被编译为
.dex
(Dalvik 可执行文件)文件,这些文件又被压缩为单个.apk
文件在设备上。.dex
文件可以通过自动翻译用 Java 编程语言编写的编译应用程序来创建。Dex 文件格式:
Android 有关于
Dalvik 可执行格式
的文档(< .dex 文件)。您可以在官方文档中找到更多信息:Dex 文件格式.dex
文件与 java 类文件类似,但它们在较旧 Android 版本上的 Dalvik 虚拟机 (DVM) 下运行,并在设备上安装时使用 ART 在较新版本上编译为本机代码安卓版本。您可以使用 android-sdk 中提供的 dexdump 工具来
反编译
.dex。还有一些逆向工程技术可以从
.dex
文件创建jar 文件
或java 类文件
。About the .dex File:
One of the most remarkable features of the
Dalvik Virtual Machine
(the workhorse under the Android system) is that it does not use Java bytecode. Instead, a homegrown format called DEX was introduced and not even the bytecode instructions are the same as Java bytecode instructions.Compiled Android application code file
Android programs are compiled into
.dex
(Dalvik Executable) files, which are in turn zipped into a single.apk
file on the device..dex
files can be created by automatically translating compiled applications written in the Java programming language.Dex file format:
Android has documentation on the
Dalvik Executable Format
(.dex files). You can find out more over at the official docs: Dex File Format.dex
files are similar to java class files, but they were run under the Dalvik Virtual Machine (DVM) on older Android versions, and compiled at install time on the device to native code with ART on newer Android versions.You can
decompile
.dex using thedexdump
tool which is provided in android-sdk.There are also some Reverse Engineering Techniques to make a
jar file
orjava class file
from a.dex
file.dex
文件是在 Dalvik VM 上执行的文件。Dalvik VM 包含多种性能优化、验证和监控功能,其中之一是 Dalvik Executable (DEX)。
Java源代码由Java编译器编译成
.class
文件。然后,dx
(dexer) 工具(Android SDK 的一部分)将.class
文件处理为名为DEX
的文件格式,其中包含 Dalvik 字节代码。 dx 工具消除了类中存在的所有冗余信息。在 DEX 中,应用程序的所有类都打包到一个文件中。下表提供了 JVM jar 文件和 dex 工具处理的文件的代码大小之间的比较。该表比较了系统库、Web 浏览器应用程序和通用应用程序(闹钟应用程序)的代码大小。在所有情况下,dex 工具都将代码大小减少了 50% 以上。
在标准 Java 环境中,Java 代码中的每个类都会生成一个
.class
文件。这意味着,如果 Java 源代码文件有一个公共类和两个匿名类(比方说用于事件处理),那么 java 编译器将创建总共三个.class
文件。Android平台上的编译步骤是相同的,因此会产生多个
.class
文件。但生成.class
文件后,使用“dx”工具将所有.class
文件转换为单个.dex
,即Dalvik可执行文件,文件。它是在 Dalvik VM 上执行的.dex
文件。.dex
文件已针对内存使用进行了优化,该设计主要由数据共享驱动。dex
file is a file that is executed on the Dalvik VM.Dalvik VM includes several features for performance optimization, verification, and monitoring, one of which is Dalvik Executable (DEX).
Java source code is compiled by the Java compiler into
.class
files. Then thedx
(dexer) tool, part of the Android SDK processes the.class
files into a file format calledDEX
that contains Dalvik byte code. Thedx
tool eliminates all the redundant information that is present in the classes. InDEX
all the classes of the application are packed into one file. The following table provides comparison between code sizes for JVM jar files and the files processed by thedex
tool.The table compares code sizes for system libraries, web browser applications, and a general purpose application (alarm clock app). In all cases dex tool reduced size of the code by more than 50%.
In standard Java environments each class in Java code results in one
.class
file. That means, if the Java source code file has one public class and two anonymous classes, let’s say for event handling, then the java compiler will create total three.class
files.The compilation step is same on the Android platform, thus resulting in multiple
.class
files. But after.class
files are generated, the “dx” tool is used to convert all.class
files into a single.dex
, or Dalvik Executable, file. It is the.dex
file that is executed on the Dalvik VM. The.dex
file has been optimized for memory usage and the design is primarily driven by sharing of data.编译好的Android应用程序代码文件。
Android 程序被编译为 .dex(Dalvik 可执行文件)文件,这些文件又被压缩为设备上的单个 .apk 文件。 Android 可以通过翻译用 Java 编程语言编写的编译应用程序自动创建 .dex 文件。
Compiled Android application code file.
Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a single .apk file on the device. .dex files can be created automatically by Android, by translating the compiled applications written in the Java programming language.