What are .dex files in Android?
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:
1. File Header
2. String Table
3. Class List
4. Field Table
5. Method Table
6. Class Definition Table
7. Field List
8. Method List
9. Code Header
10. Local Variable List
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 Dalkvik 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 the dexdump
tool which is provided in android-sdk.
There are also some Reverse Engineering Techniques to make a jar file
or java class file
from a .dex
file.
What is .dex file in android? I am getting an error Multiple dex files define Lorg/springframework/core/NestedRuntimeException;
.dex
means Dalvik EXecutable. It is the format the DVM
(Dalvik Virtual Machine) needs. The DVM is used by Android as runtime enviroment.
Your .apk
-files contain those .dex
ones (rename .apk
to .zip
and see for yourself).
So your Java-source has to be translated to .dex, that should be done by your Android-SDK when building your .apk. At this step, it seems to me, something goes wrong and therefore you get an error at runtime.
Check your code and see if you can do something about:
Multiple dex files define Lorg/springframework/core/NestedRuntimeException;
Is .dex file also used when we run android app in physical mobile?
DEX is the file format for the compiled bytecode that goes into an APK file. It will be used on devices and emulators.
Note that DDMS has not been used in years. I recommend that you check the dates on the materials that you are reading and focus on newer items.
Difference between AAR, JAR, DEX, APK in Android
JAR (Java Archive)
JAR is a package file format designed for distribution of Java application on its platform. It contains compiled Java class files + some more files like MANIFEST. Basically it is just an ZIP archive with some restrictions.
DEX (Dalvik Executable)
DEX is binary file format, so it is compiled. We could say, that .dex file is for DVM (Dalvik Virtual Machine) something like .class files for JVM.
DEX file format is really generated from java CLASS files by dex compiler from Android SDK. This compiler translates JVM bytecode to DVM bytecode and put all class files to one dex file.
APK (Android Application Package)
APK is file format designed for distributing Android application on its platform. It has some similarities with JAR format. Again it is simply just a ZIP archive, but APK files have pre-defined specific structure. For example, it always must contains file named AndroidManifest.xml and many more. Also this package aggregates compiled classes in dex format.
AAR
AAR is the binary distribution of an Android Library Project. It has similar structure as APK.
Format of .dex files for Android 2.1 (Eclair), i.e. API level 7
https://source.android.com/devices/tech/dalvik/dex-format has some quick blurbs on the differences between the versions.
Note: Support for version 037 of the format was added in the Android 7.0
release. Prior to version 037 most versions of Android have used version 035 of
the format. The only difference between versions 035 and 037 is the addition of
default methods and the adjustment of the invoke.
Note: Support for version 038 of the format was added in the Android 8.0
release. Version 038 added new bytecodes (invoke-polymorphic and invoke-
custom) and data for method handles.
Although, note that the newest version is 039, which doesn't seem to be mentioned in the doc. iirc, 039 added the invoke-custom/range
, const-method-handle
and const-method-type
instructions.
Other sources of information include looking at the changelog of those documents:
https://android.googlesource.com/platform/docs/source.android.com/+log/refs/heads/master/en/devices/tech/dalvik/dex-format.html
https://android.googlesource.com/platform/docs/source.android.com/+log/refs/heads/master/en/devices/tech/dalvik/dalvik-bytecode.html
And prior to that, before the files were moved:
https://android.googlesource.com/platform/docs/source.android.com/+log/a3b748b40bab557fb47fe5a48a5bfb642837fb05/src/devices/tech/dalvik/dex-format.jd
https://android.googlesource.com/platform/docs/source.android.com/+log/a3b748b40bab557fb47fe5a48a5bfb642837fb05/src/devices/tech/dalvik/dalvik-bytecode.jd
Also, you should be able to glean some info from the smali source. It has the min/max api levels, where applicable, for every instruction.
For the instructions with the min/max set as an art version, you can use this mapping to map back to an api level.
Related Topics
How to Securely Store Access Token and Secret in Android
When to Clear the Cache Dir in Android
System.Exit(0) Doesnt Close All My Activities
Passing Strings Between Activities in Android
How to Make an Http Request Using Cookies on Flutter
Retrieving a List of Users Who Have Registered Using Firebase Auth
Accessing Contents of R.String Using a Variable to Represent the Resource Name
Android Listview Using Viewholder
How to Simulate Android Killing My Process
Which Websocket Library to Use in Android App
Android - Acceleration Down (Smash)
Android Emulator: How to Monitor Network Traffic
Expandablelistview - Hide Indicator for Groups with No Children