How to decompile android apk to java source code?

Updated Post: https://codexplo.wordpress.com/2013/03/22/how-to-decompile-android-apk-to-java-source-code-2/

I think it’s very often we want to explore the existing projects source code but again sometime it may not be  available. Personally I love to dig on existing project to know how people write their codes.

Suddenly I thought, if there is any apk to java source decompiler, it would be a nice thing.  You probably know, android runs on dalvik virtual machine, so when we compile android java code, its compile to dex( dalvik executable). So I search a lot to find a way how to convert dex to jar ,and I know already how to decompile jar file to java source code.

At last I found the way out.

Here is the way-

You will need-

  1. Eclipse IDE
  2. Java Runtime (of course)
  3. JD-GUI or JD Eclipse plugin
  4. DexToJar (get them from here: http://code.google.com/p/dex2jar/)

And now follow the steps

Step 1:  Create a java project, name it DexToJava.

Create a java project

Step 2: Create a folder and name it libs. Paste all jars file in the libs folder after extracting dex2jar-0.0.9.8.tar.gz . Go to build path. Add all the jars in the build path.

Step 3: You are almost done.  Get an apk file and paste it in your project. For me it is facebook.apk.

Step 4: right click on project and select run as.  Set main class: com.googlecode.dex2jar.v3.Main

Step 5: Set Argument facebook.apk and now click on apply and run it.

Step 6: after completing the job, you will find on console:

Step 7: now refresh the project, and you will find facebook_dex2jar.jar. And you know already how to get java source from jar. Use JD-GUI.

That all.

I think you enjoy it.

41 thoughts on “How to decompile android apk to java source code?

  1. But nowadays people are obfuscating there code , so after decompiling also it will not help us. Do u have any solution for this.

    1. decompiling obfuscating code would be difficult. sorry i have no idea right now, if i get the solution, surely i will post the solution here, stay tuned. thanks.

  2. This is a great start but the instructions are very incomplete. Step 5 was the worst for the argument. What you should do is go to the Argument tab, select File promt and click OK, then apply. Then Run. It will prompt you for the location of the .APK file. Then it will finally create the jar file.

  3. about step 7. no, i actually don’t know how to get java source from jar. that’s why i read your article. which was helpful, but not straightforward. next time try not to skip with the details. what might seems simple and clear to one, not always the same for the other.
    thanks anyway

  4. Hi Bazlur Rahman,
    I ‘ve problem which not clearly in step 5. I ‘ve already seen the picture in step 4.
    But I don’t know that how to set Argument after select Argument tab? Please show me the picture.

  5. yes way, nicely worked! but i am getting $ sign in file names. for eg: original HomeForm.java results in HomeForm.java, HomeForm1.java and HomeForm2.java.
    are these files part of code or should i delete those files and keep only HomeForm.java?

  6. First, thank you for the tutorial. I disagree about ambiguity in step 5. For a novice eclipse user, it wasn’t that hard. I imagine that your tutorial assumes a certain level of proficiency on the part of the student…

    That said, may I ask for a bit of guidance?

    I followed your steps. I used Windows Explorer to create folder, copy/past .jar files. I told Eclipse to include them and saw them in the project. I set main class to com.googlecode.dex2jar.v3.Main but when I set the argument to my xxxxxxx.apk and clicked run, I received an immediate message: ERROR: com.googlecode.dex2jar.v3.Main could not be found.

    Where am I missing a step? I have the Android SDK installed. Should I create the new project as an Android project rather than a java project?

    Thanks in advance,

    Fulano

  7. Hey …
    I have message in consol like as following:

    “this cmd is deprecated, use the d2j-dex2jar if possible
    dex2jar version: translator-0.0.9.13
    dex2jar file1.dexORapk file2.dexORapk …”

    I have followed all above step properly. So please help me asap

  8. hey m gettin following error:
    do help…
    this cmd is deprecated, use the d2j-dex2jar if possible
    dex2jar file1.dexORapk file2.dexORapk …
    dex2jar version: translator-0.0.9.13

  9. Hi Bazlur Rahman,
    First of all thanks a lot for this great tutorial, such an amazing much needed, so useful keep it up God Bless You
    Using this Tutorial, I am able to get Java, XML files, resources, drawables, manifest etc.
    Actually i am facing some issues in Java code, in short getting many Errors like:
    1. The type of the expression must be an array type but it resolved to Object
    2. Type mismatch: cannot convert from int to LinearLayout
    3. Type mismatch: cannot convert from LinearLayout to int
    4. The method setVisibility(int) in the type View is not applicable for the arguments (LinearLayout)
    5. Type mismatch: cannot convert from int to boolean
    6. – monitorenter cannot be resolved to a variable
    7. – Syntax error, insert “AssignmentOperator Expression” to complete Expression
    8. The label label175 is missing
    9. The local variable localObject may not have been initialized
    Thanks again, i will wait for your reply…

  10. dex2jar version: translator-0.0.9.15
    this cmd is deprecated, use the d2j-dex2jar if possible
    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/io/FilenameUtils
    at com.googlecode.dex2jar.v3.Main.main(Main.java:83)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FilenameUtils
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 1 more
    —————————————————————————————-
    what can i do ? plz help me ?

  11. I have tried to extract code from .apk file.I didnt get R.java file and in java code i am seeing lot of absolute values instead of R.id.___ .

    how to rectify it ??
    please help…!!

    thanks a lot in advance…!

  12. Hi,

    I followed every instruction and i get this error.

    Error: Could not find or load main class com.googlecode.dex2jar.v3.Main

    Do you have any idea what I might have done wrong?
    I was thinking the dex2jar.bat file is located in the wrong place.
    But I am not sure as to where I should put it…

Leave a comment