How to convert class file to dex file in android? Is there any way?
The classes. dex file is a Dalvik Executable file that all Android applications must have. This file contains the Java libraries that the application uses. When you deploy an application for Android, RAD Studio includes a classes.
First you need a tool to extract all the (compiled) classes on the DEX to a JAR. There's one called dex2jar, which is made by a chinese student. Then, you can use jd-gui to decompile the classes on the JAR to source code. The resulting source should be quite readable, as dex2jar applies some optimizations.
During work, JVM dynamically reads in bytecode to each . class file in case the class is required. Meanwhile in DVM, the bytecode of all the classes is in one . dex file (Dalvik Executable).
Invoke "dx" command with "--dex" option like the following.
dx --dex --output=<output-file> <input-file>
"dx" command is contained in Android SDK. The location of the command varies. Try to search:
<SDK-HOME>/platform-tools/
<SDK-HOME>/platforms/<platform>/tools/
"dx --dex" can accept some options. For example, "--no-strict" option will skip checking whether path names of input class files match the declared package/class names, so you'll get a different result for WebService.class if you invoke dx with this option. Probably, "--keep-classes" option is useful if you want to use jar files on both Android and Java SE. Without "--keep-classes" option, dx command replaces all .class files in an input jar file with one file named "classes.dex", but with "--keep-classes" option, input .class files also go into the ouput file as well as classes.dex.
ex:
dx --dex --keep-classes --output=output.jar input.jar
I read the source code of dx and listed up the command line options with some explanation at the following page.
Usage of dx --dex:
http://darutk-oboegaki.blogspot.com/2011/03/usage-of-dx-dex-dx-dex.html
Use dx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With