Decompile .smali files on an APK

JavaAndroidApkSmali

Java Problem Overview


I downloaded APK Manager that lets me unpack APK files.

But it only unpacks it and doesn't decompile the .smali file to .java.

Is it possible to decompile the .smali to .java?

Java Solutions


Solution 1 - Java

No, APK Manager decompiles the .dex file into .smali and binary .xml to human readable xml.

The sequence (based on APK Manager 4.9) is 22 to select the package, and then 9 to decompile it. If you press 1 instead of 9, then you will just unpack it (useful only if you want to exchange .png images).

There is no tool available to decompile back to .java files and most probably it won't be any. There is an alternative, which is using dex2jar to transform the dex file in to a .class file, and then use a jar decompiler (such as the free jd-gui) to plain text java. The process is far from optimal, though, and it won't generate working code, but it's decent enough to be able to read it.

dex2jar: https://github.com/pxb1988/dex2jar

jd-gui: http://jd.benow.ca/

Edit: I knew there was somewhere here in SO a question with very similar answers... https://stackoverflow.com/questions/1249973/decompiling-dex-into-java-sourcecode

Solution 2 - Java

There is a new cross plateform (java) and open source tool, that enable you to do that, just checkout https://bytecodeviewer.com

enter image description here

=========

EDIT: As of April 2017, there is a new open source tool developed by google, that is meant to do just what we have been looking for => https://github.com/google/android-classyshark

Solution 3 - Java

dex2jar helps to decompile your apk but not 100%. You will have some problems with .smali files. Dex2jar cannot convert it to java. I know one application that can decompile your apk source files and no problems with .smali files. Here is a link http://www.hensence.com/en/smali2java/

Solution 4 - Java

My recommendation is Virtuous Ten Studio. The tool is free but they suggest a donation. It combines all the necessary steps (unpacking APK, baksmaliing, decompiling, etc.) into one easy-to-use UI-based import process. Within five minutes you should have Java source code, less than it takes to figure out the command line options of one of the above mentioned tools.

Decompiling smali to Java is an inexact process, especially if the smali artifacts went through an obfuscator. You can find several decompilers on the web but only some of them are still maintained. Some will give you better decompiled code than others. Read "better" as in "more understandable" than others. Don't expect that the reverse-engineered Java code will compile out of the box. Virtuous Ten Studio comes with multiple free Java decompilers built-in so you can easily try out different decompilers (the "Generate Java source" step) to see which one gives you the best results, saving you the time to find those decompilers yourself and figure out how to use them. Amongst them is CFR, which is one of the few free and still maintained decompilers.

As output you receive, amongst other things, a folder structure that contains all the decompiled Java source code. You can then import this into IntelliJ IDEA or Eclipse for further editing, analysis (e.g. Go to definition, Find usages), etc.

Solution 5 - Java

I second that.

Dex2jar will generate a WORKING jar, which you can add as your project source, with the xmls you got from apktool.

However, JDGUI generates .java files which have ,more often than not, errors.

It has got something to do with code obfuscation I guess.

Solution 6 - Java

For getting the practical view of converting .apk file into .java files just check out <https://www.youtube.com/watch?v=-AX4NYE-9V8> video . you will get more benefited and understand clearly. It clearly demonstrates the steps you required if you are using mac OS.

The basic requirement for getting this done.

  1. http://code.google.com/p/dex2jar/
  2. http://jd.benow.ca/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBimoZXView Question on Stackoverflow
Solution 1 - JavaAleadamView Answer on Stackoverflow
Solution 2 - JavaGominoView Answer on Stackoverflow
Solution 3 - JavaDarynView Answer on Stackoverflow
Solution 4 - JavaChristophView Answer on Stackoverflow
Solution 5 - JavaAvijitView Answer on Stackoverflow
Solution 6 - JavaParamView Answer on Stackoverflow