Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert class file to dex file

Tags:

android

How to convert class file to dex file in android? Is there any way?

like image 753
Dhanush Avatar asked Nov 12 '10 09:11

Dhanush


People also ask

What are classes DEX files?

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.

How do I decompile a .DEX file?

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.

What is the difference between .class and .DEX files?

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).


2 Answers

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

like image 59
darutk Avatar answered Oct 29 '22 17:10

darutk


Use dx.

like image 23
Valentin Rocher Avatar answered Oct 29 '22 17:10

Valentin Rocher