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-
- Eclipse IDE
- Java Runtime (of course)
- JD-GUI or JD Eclipse plugin
- 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.
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.
Hello. How do you do the step 5? Where do you set the argument to your apk file?
right click on your project, goto run as, then select run configuration..
right click>Run As>Run Configuration..
I hope you will get it now .
Take a look at AndroChef Java Decompiler: http://www.neshkov.com/ac_decompiler.html
It is much easier.
But nowadays people are obfuscating there code , so after decompiling also it will not help us. Do u have any solution for this.
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.
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.
Uuseefull link
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
Yes, I agree with you 100%
hey can you just read my previous post. It was 2nd part of that tutorial . https://codexplo.wordpress.com/2012/03/15/java-decompiler/
any way thanks for reading..
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.
just write facebook.apk on the argument tabs text area, it will work..
impossible de trouver ou charger la classe principale com.googlecode.dex2jar.v3.Main!!!!!!!!
Please write in English… thanks
i have completed .apk to .jar , i want to know how to get java source from jar ……
Follow this link
https://codexplo.wordpress.com/2012/03/15/java-decompiler/
thank you …..
You’re welcome 🙂 you can like facebook my page now 😀
Thank u. Helped me a lot to Develop a app in One Day 🙂
You’re welcome 🙂 you can like my facebook page now 😀how to decompile xml files alone from .apk without using java decompiler….
please explain how to set the argument in 5 th step……..
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?
hi it is very usefull
But one dought … Emulator is Working or not Bluetooth code
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
hey, I have updated the post, see here https://codexplo.wordpress.com/2013/03/22/how-to-decompile-android-apk-to-java-source-code-2/,
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
how about reading : https://codexplo.wordpress.com/2013/03/22/how-to-decompile-android-apk-to-java-source-code-2/
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
how about reading this: https://codexplo.wordpress.com/2013/03/22/how-to-decompile-android-apk-to-java-source-code-2/
hi, can you also show how to import the decompiled source code in eclipse..
every time i import a decompiled apk folder to the eclipse, the src folder in eclipse shows numerous errors..
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…
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 ?
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…!
You can’t get that .
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…
Getting error. Don’t follow this link…
Is there any procedure to extract native libraries from apk file.
for those who suffered from class load error, try solution in http://stackoverflow.com/questions/1249973/decompiling-dex-into-java-sourcecode which solve my problem.