How can I programmatically decompile dex files within Android? How can I programmatically decompile dex files within Android? xml xml

How can I programmatically decompile dex files within Android?


You can browse the sourcecode of the ShowJava application here. It looks like he is using the the Dex2Jar tool. The decompilation starts in a BackgroundService and all the magic happens in some special Jar classes. I do not know if this code comes from a library or if all this code is created by him. Look at the ExtractJar and the DecompileJar method than it shouldn't be to hard to understand what's going on.


You need to follow some steps in order to get it working:

  1. Got to the dex2jar bitbucket site and download the files. Add the jar files to your project.
  2. Via the DexFileFactory, you can load the apk, convert it to dex (loadDexFile) and save it to a file (writeDexFile).
  3. With another library that converts jars to java-files, you can finally read the content. I found Procyon, which seems really simple. Load the class file with an InputTypeLoader and then call Decompiler.decompile().

Of course you can use other libraries in step 3, but for step 1 and 2, I haven't found any alternatives.