Now time for backtracking…start your time to do hacking. Do you know you can get source code of Android APK file? Time to break the code..Let’s learn step by step.
In this tutorial we will learn how to convert android APK file into source code. Android .apk file is a compressed form of a file which contains Java classes (in .dex form), XML files and all necessary files. So first we will learn how to get Java source File from android apk using dex2jar and Java decompiler tools and then we will learn how to get XML source file using apktool and apkinstall tools.
To get the source code from APK file, we will need these tools:
1. dex2jar
2. java decompiler
3. apktool
4. apkinstall
Steps to get source:-
Get Java files from APK:-
1. Rename the .apk file into .zip file (example SharedPr.apk into SharedPr.zip).
2. Extract SharedPr.zip file and copy classes.dex file from extracted folder.
3. Extract dex2jar.zip and paste classes.dex into dex2jar folder.
3. Open command prompt and change directory to the dex2jar folder. Then write dex2jar classes.dex and press enter. Now you will get classes.dex.dex2jar file in the same folder.
Convert classes.dex to classes.dex.dex2jar |
4. Now double click on jd-gui(Java decompiler) and click on open file. Then open classes.dex.dex2jar file from that folder. Now you will get class files and save all these class files (click on file then click “save all sources” in jd-gui) by src name.
classes.dex.dex2jar will be in dex2jar folder |
Save All Java Files |
Get XML files from APK:-
1. Extract apktool and apkinstall in a folder(Example : New Folder).
2. Put SharedPr.apk(your apk file) in same folder(i.e New Folder).
Keep Android Apk File with apktool and apkinstall |
3. Open the command prompt and go to the root directory(i.e New Folder).
4. Type command on command prompt: apktool d SharedPr.apk
Get All XML Files In Resource Folder |
5. This will generate a folder of name SharePr in current directory (here New Folder) and all XML files will be in res->layout folder.
See All XML Files in new created Folder |
Now you have source code. If you have any doubts please comment. Share and help others.
Note:- Video of this post is also available on YouTube, Watch video "How to get source code (Java code and XML code) From Android APK File".
Note:- I disabled comment option on this post because I was getting lots of comment on this post. I updated download links & if anybody facing any problem than contact me directly.
For more related to Android tutorials see List of Android Tutorials.
Related Tutorials:-
★ Display Time using Broadcast Receiver
★ Warning: No DNS servers found in Android Eclipse
★ Run two or more instances of emulator at a time
★ Emulator error at runtime: std::bad_alloc
★ Swipe Left and Right using Gesture Detection
very good nice sharing...
ReplyDeletejava decompiler link show this error
ReplyDeleteErreur 403 - Refus de traitement de la requĂȘte (Interdit - Forbidden)
May be file moved..but I updated and used your given URL and Thanks dear.
DeleteI am only getting a smali folder and no XML files at all. I am following every step perfectly.
Deleteeven I got smali folder
Deletewhat I did after that is, I have Downloaded the latest version of apktool. https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.0.1.jar
extract it rename it "apktool" and then it should work
i tried on this one is this correct...???
ReplyDeletehttp://jd.benow.ca/
yeah this is correct. Thanks for sharing.
DeleteThanks I used this URL also.
ReplyDeletei tried i didnt get any res folder etc..
ReplyDeleteTry again I updated post with images. This will help you.
Deletehow accurate is the java code with this tool??
ReplyDeleteit gave me 100% result.
Deletem getting an error everytime i try to apktool !! [even though i run with admin rights]
ReplyDelete_________________________________________________________
apktool d prov.apk
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
at brut.androlib.ApkDecoder.hasSources(ApkDecoder.java:199)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:83)
at brut.apktool.Main.cmdDecode(Main.java:146)
at brut.apktool.Main.main(Main.java:77)
Caused by: brut.directory.DirectoryException: java.util.zip.ZipException: error in opening zip file
at brut.directory.ZipRODirectory.(ZipRODirectory.java:55)
at brut.directory.ZipRODirectory.(ZipRODirectory.java:38)
at brut.androlib.res.util.ExtFile.getDirectory(ExtFile.java:55)
at brut.androlib.ApkDecoder.hasSources(ApkDecoder.java:197)
... 3 more
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:127)
at java.util.zip.ZipFile.(ZipFile.java:144)
at brut.directory.ZipRODirectory.(ZipRODirectory.java:53)
... 6 more
Read and apply this method again and with different apk file. If you failed than send me your apk file.
DeleteWhere i can send apk file ?
DeleteBro.. First always try yourself to learn and now this tutorial is also available on Video. So you can easily learn.
Deletei tried alot, i am stuck at > 3. Open command prompt and change directory to the dex2jar folder. Then write dex2jar classes.dex and press enter. Now you will get classes.dex.dex2jar file in the same folder.
Deletedid you seen video?? and are you not getting classes.dex.dex2jar??
DeleteI am getting the same error and no XML files.
Deletetype d2j-dex2jar classses.dex in command prompt
DeleteHello
DeleteDo not bother
I had this problem and I was very much looking solution
Loved this problem is solved with the following code
java -jar apktool.jar d -f -r apkfilename.apk
Thanks
This comment has been removed by the author.
DeleteThis comment has been removed by a blog administrator.
Deletehello ,
ReplyDeletei am sucessfully decompiled but m not open in eclips so please hell me
If you got resource file(all XML files and images) and all Java files than create new android project and use them.
ReplyDeleteI used the video and it all worked. Now, I've got loads of files here, to include a folder with java and a folder with XML. How do I build all of this into an editor to start playing around with it? I have dreamweaver (trial) but I'm open to lean another editor.
Deleteif you dont mind if i ask if you do you have the decode file of flow free game? thanks
DeleteMohsin bhai...!! one critical question...
ReplyDeleteIs it possible to make an android app that can't be decompiled? It will be needed sometimes in case of security application???
You can provide security on some code but how? i don't know this also. I tried to get code of WatsApp Application and failed to get complete code but i got all resources files and partially all Java files(some parts gave error on decompile)
DeleteI ecxtracted the apk file but i dont know, how to understand the coding in GUI... Can u able to help me?
ReplyDeleteIf you are beginner in android than don't try decoding..try to learn code and than learn decoding. If not than share your code we will help you.
DeleteERROR SHOWING:
ReplyDelete"apktool d myfile.apk"
message frm cmd: 'apk tool is not recognsed internal or external command, operable program or batch file'
correct your path folder or watch video of this post.
Deletei finally managed to decomile app app but i ddnt know how to arrange the arts so that i can run it into eclipse please help..
ReplyDeleteyou have to make new android project and paste all Java files and XML files manually.
DeleteHey Bro,,, Is it possible to get the source code of an app in playstore using this method?? Plz reply its for my College project!!!
ReplyDeleteYou have to keep APK file for this method(download from website). You cant get apk from Google Play Store.
DeleteOh,,,, k,,, could u plz get me the code for an android anti theft app,,, I tried bt can't get the apk file.
DeleteYou can get apk file of any google play application by using any "apk extractor"
DeleteUse "Helper Plus" app to get apk.
DeleteI done all the steps and i imported in eclipde but it showed error in R.java what can i do
ReplyDeleteI have got XML files and java source code in two different folders. How can I combine them, so as to Import them into Eclipse for tesing purpose??
ReplyDeleteSir Help me to I am Not able to get full source code of this app https://play.google.com/store/apps/details?id=com.tenforwardconsulting.simplefit
ReplyDeletePlease Help me to provide it
I am A B.Tech sudent and My project is simple fitness app :)
if you have a app with source code please send it to me
Thank you
i need it
DeleteHello bro,
DeleteCheck where you are getting problem please tell.
my command propmt always
ReplyDeletejava is not recognized.....error ???????
Set Java Path first than do.
Deleteit has worked on my PC perfectly thanks anyway
ReplyDeletedo you know how to import all files true without errors into eclipse?
you need to make a new project and all extracted codes are only for knowing logic not complete code because all integer and string changed into hexa-decimal value at compile time.
DeleteSir please can you teach me how to do it step by step? bcz I really need it and I have only a bit knowledge in Android development...
Deleteif possible can you send to my email how to change or add into source:
iris.org.baron@gmail.com
thanks and really
appreciate beforehand
If you have little bit knowledge of android than it is better to learn from basic and create project yourself because source code will not help you to make your project.
DeleteI just opened an xml document on dreamweaver and a lot of it is scrambled. must be hexadecimal value stuff you mentioned interrupting it. Yeah, I'll have to build it from scratch.
DeleteBaRoN, I just googled a little and found this: http://developer.android.com/training/basics/firstapp/index.html
Everything works good extracting the source code from the APK. Great Tutorial. However the source code extracted is not running in development environment. Can you make a tutorial on how to run it Eclipse once extracted. This would be Perfect
ReplyDeleteI can't remember which one of these tutorials covered Eclipse. One of these will cover it in detail:
Deletehttp://docs.oracle.com/javase/tutorial/getStarted/index.html
http://developer.android.com/training/basics/firstapp/index.html
I'll be starting off with android's tutorial first. Editing a packaged app is not the same as getting html source code and files and editing it on an html editor. This is complicated stuff but the tutorials look really good.
Hello ... When i convert .apk into .zip ... after unzipping there is no .apk file show in extracted folder .... Help
ReplyDeleteThis comment has been removed by the author.
Deletehey khizar you have to keep original apk file with you...
DeleteThanks :)
Deletehi Khizar.....yaar m also getting this same problem..please help me....
ReplyDeleteExtracted file only for understanding the application ... We cant convert exact the code ...
Deletehi its great......now i have got aal source code and xml code...bt when i m import this code in adt(android development tool) it dont show the sjava code..source code folder not opened their...what can i do..please help me its urgent...
ReplyDeletecongrats...you have to create new project to use extracted code. Extracted code is only for help to know logic not complete code.
Deleteis it possible to import these files into eclipse workspace
ReplyDeletei try to get code for "AndroidUSBSerialMonitorLite" this apps.. i got the java code and xml files... using these files i try to create a new new project.. its showing an error like "Android Library Projects Cannot Be Launched" :(
ReplyDeletewhat can i do??? can you give me some ideas?? i hope these apps contains some library files and we have to add... how to add these library files???
If APK file have library files than you have to download from net.
Deleteit works bro but how to arrange them?
ReplyDeletecause i m not android developer and i didnt know android....!!!!
i use different method and i get 4 folders (assets, res, smali, src), 1 XML file (AndroidManifest)....
now what can i do?????
i have to run this apps in android eclipse ide
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHey
ReplyDeleteI have problem while compile problem.
I see lib and apktool.yml is missing.
Please help me.
Super Tutorial..
ReplyDeleteThank you.
Thanks
ReplyDeletei can't extract xml files .. it shows unable to acess jarfile
ReplyDeletei tried dwnload from other source but still shows same result
please help me
thank u
This comment has been removed by a blog administrator.
ReplyDeletePlease How can I get the video?
ReplyDeleteThis comment has been removed by the author.
ReplyDeletePlease Dear I'm developing an android RSS Reader application but I don't know where to start. please can you be of help to me?
ReplyDeletehi
ReplyDeletei want to change in my apk file these thing..
1. about
2. in share opition
3. and i could not set score in my apk file..
how i change these three things in my apk file.
plz tell me
Hie sir,
ReplyDeletewhen i'm converting the apk file to get the xml files im getting an error
:
C:\Users\Nikki\Desktop\xml files>apktool d com.pandutechnology.phoneadd
pk
I: Baksmaling...
I: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: Multiple re
spec=0x7f050000 dimen/title_height, config=-v13
at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:
at brut.androlib.res.data.ResConfig.addResource(ResConfig.java:
at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.
at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder
)
at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.j
at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecode
5)
at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.jav
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(An
ources.java:315)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibReso
a:50)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibReso
a:43)
at brut.androlib.Androlib.getResTable(Androlib.java:44)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
at brut.apktool.Main.cmdDecode(Main.java:120)
at brut.apktool.Main.main(Main.java:57)
Plzz help me
It seems there's some problem in building the resources while recompiling the apk. what you can do is, when you decompile your apk use this command
Deleteapktool d -f -r apkfilename.apk
here -f is to replace previous decompiled apk's code and -r is to ignore the decompiling of resources.
this would prevent the resources from being decompiled and will simply copy the same resources when you recompile the ap
thanx
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteDon't try to share your valueless link..i deleted many times.
Deleteawosome.....I really needed that
ReplyDeleteHi,
ReplyDeleteI have got all source code and xml file from my own app apk file...but
after importing it into new project .java file is not working..its show code unreachable error...why its came?
Extracted code only for help to know logic..you have to write your own code.
DeleteHi,
ReplyDeleteI cant get xml files."apktool is not recognizable as internal or external batch".This is the error i get.Help me to resolve this error.
Regards,
Gokul P
Set Java path first bro...Google it "how to set java path"
Deletebro thanks for the help..u did a great job..
Deleteregards,
P.Gokul
you will get XML folder and smali folder both with this method.
ReplyDelete13.2 MB size of *.apk file does not convert into resouses by using jd-gui-0.3 softawre and it does not save all resource option and after 10sec software is close.....why
ReplyDeleteso,give me answer of above Question and send feedback on emailid Email:-durgeshchandole19@gmail.com
hello sir
ReplyDeletei have one problem one time i open apk file in notpad++ so how to open again in apk format i dont understand how i do
so ple help me
i am still wait your response khushjoshi93@gmail.com
thank you
Just go to Application manager and find Notepad++ and disable button for launch activity default.
DeleteAwesome tutorial, thanks a ton.
ReplyDeleteWorked in one go ! without any problem.
(y) (y) (y)
By the way may i ask what is that smali thing ?
(Just for knowledge)
i get whole code using above step..but when i extract xml file there is generate a one folder name is smali...what is this folder?? n..and open the xml file in eclips .it will give error like below...
ReplyDeleteNOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- com.wAmityUniversity.Views.TransparentPanel (Fix Build Path, Edit XML, Create Class)
In large size APK Files, This problem may occur...
Deletesir apk to source is converted but layout code is encrypted now what can i do
ReplyDeleteplease help....my mail id is jvijay2106@gmail.com
please help me extract xml file
ReplyDeletenot getting apktoool.jar
I have apktool.bat and aapt with my apk file please help how to extract or get apktool.jar
it shows and error unable to access jar file
DeleteI just don't getting apktool.jar and have apktool
please tell me path were I could get or extract please help
same here
DeleteThank u buddie
ReplyDeleteIs need to install "framework-res.apk" and run this command : apktool if framework-res.apk before apktool d SharedPr.apk
ReplyDeleteNo..
DeleteIf you possible, tell about the folder structure after did all your steps ?
ReplyDeletehow can i import my project in eclipse ??
ReplyDeleteplz give me your email address i am not getting the xml code from an app. so plz do it for me plz give me your email id so i can send you my apk file.
ReplyDeleteDid you ever think is it possible to edit an APK file or change the way it works?
ReplyDeletehttp://goo.gl/rv6JRT
I am not getting the "res>layout" folder.
ReplyDeleteHello, great tuto thanks for it.
ReplyDeleteI'm facing a strange problem: I get the right java files but the old res files. All drawables, strings, layout... are from the first version I published.
Is there a way to get the latest res files from the apk?
Thank you.
thank you that post this session
ReplyDeletemy program does not run into emulator and when i run this programm into MOBILE simple helllo world program run but when i set any object it is not work
ReplyDeleteon right clicking on zip file.what is now the option so to click
ReplyDeleteHello, is there a way to get the exact code as it is in the original class?
ReplyDeleteFor example, a line from my original file is, setContentView(R.layout.activity_main);
but the decompiler output of the same line is setContentView(2130903063);
Thanks.
P.S I have but a little experience in Android
nice post, success with 1 shots .. :)
ReplyDeletewill it work in win 8.1?
ReplyDeletei didn't get xml files. no folder was created in new folder
Another great one from you, saw your video on youtube too but whenever I try to use cmd to go to C:\Users\Akash\Desktop\dex2jar-0.0.9.15>dex2jar classes.dex... Then I hit enter & comes this message : "'java' is not recognized as an interval or external command, operatble program or batch file." ??!!! Followed & understood all the steps u've shown in the video. Please I'll be really glad if u help me. Thanks in advance.
ReplyDelete& I tried to do this in several apk s, but this same result keeps coming on & on.
DeleteFigured it out by myself! Updated the PATH Environment Variable & dat solved the problem...
DeleteCould you plz. tell me how can i use (join) these java and xml files collectively to make a complete android application project in eclipse....
ReplyDeletevery nice
ReplyDeleteplease i want the code of this app
ReplyDeletehttps://play.google.com/store/apps/details?id=com.voicetotext.android
but a can"t get it please help my
how to import those file into eclipes
ReplyDeletehow to import thiz file in eclipse ,i cant import thz file
ReplyDeletePlease send me apktool and apkinstall .zip file
ReplyDeleteI can't extract this file - apktool_2.0.0rc4.jar
My mail id- lakinkintu@gmail.com please reply me as soon as possible
Any one can help me, how to extract .xml file form .apk file?
ReplyDeletegetting the error as below.....plz help me
ReplyDeleteI: Baksmaling...
testI: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode ars
c file
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:55)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:315)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.jav
a:50)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.jav
a:43)
at brut.androlib.Androlib.getResTable(Androlib.java:44)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
at brut.apktool.Main.cmdDecode(Main.java:120)
at brut.apktool.Main.main(Main.java:57)
Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000
at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48)
at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:45)
at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:97
)
at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
... 8 more
please help me .....its urgent
Deletei got the code correct for other apk files......but i want for a particular apk file
DeleteIn step 3 when i write dex2jar classes.dex
ReplyDeleteit shows the following error
dex2jar is not recognized as internal or external command
Same problem is occured with me also.plz help me.
Deletehello Mr. thanks for information but i have seen new contents in the link http://code.google.com/p/dex2jar/ is there another way to implement on it other than previous one because it seem not to work on it if there other ways please update me otherwise inform whether it has worked with you with previous way
ReplyDeleteAfter decompile am getting only smali folder no res folder generated.Also while decompiling getting error . Below error comes because of Proguard on coded. So is there any solution.
ReplyDelete*Error*
I: Baksmaling...
I: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode ars
c file
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:56)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibRes
ources.java:491)
in step 3 when i write dex2jar classes.dex
ReplyDeleteit shows the following line-
'dex2jar' is not recognised as an internal or external command,operable program or batch file.
same goes for me
Deletesame goes for me
Deletehow to edit source code and build new apk?
ReplyDeletePlease let me know if there is another way avialable apart from apktool to get the XML files from apk
ReplyDeleteHello Mohsin! I was going through your tutorial to extract the XML files and source code from the apk, and I achieved it! thanks for the valuable information. Now what I am having trouble with is building the app in android studio with these files. How can I merge then xml files and the source code to make the project work? I appreciate any advice! thank you!
ReplyDeleteif you got that error.
ReplyDeleteException in thread "main" brut.androlib.AndrolibException: Could not decode arsc file
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:52)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:538)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:63)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:55)
at brut.androlib.Androlib.getResTable(Androlib.java:64)
at brut.androlib.ApkDecoder.setTargetSdkVersion(ApkDecoder.java:209)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:92)
at brut.apktool.Main.cmdDecode(Main.java:165)
.........................................
"***** UPDATE YOUR APK TOOL JAR **********"
FROM THE LATEST
https://bitbucket.org/iBotPeaches/apktool/downloads
I SUGGEST THIS ONE
apktool_2.0.0rc4.jar
KEEP SMILE...
BUT REPLACE, THE NAME APKTOOL_2.0.0RC4.JAR WITH SAME NAME WITH THE LAST YOU HAVE AT SAME FOLDER...
DeleteHi, i cannot extract xml code because the apkinstall link is broken..can you reupload?
ReplyDeleteHi, you will found bitbucket url ..google it.
DeleteNote: Tools location moved from code.google.com to bitbucket.com
Hi,
ReplyDeleteI got java files nd while getting Xml , there is no Done written here, so is it okay or not plz suggest me ..
c:Users\Mehrish\Desktop\XML>apktool d M.apk
I:Using Apktool 2.0.2 on M.apk
I:Loading resources table...
I:Decoding AndroidManifest.xml with resources...
I:Loading resource table from file:c\user\Mehrish\apktool\framework\1.apk
I:Regular manifest package...
I:Decoding file-resources...
I:Decoding values */*XMLs...
I:Baksmaling classes.dex...
I:Copying assets and libs...
I:Copying unknown files...
I:copying orginal files..
C:\user\Mehrish\Desktop\XML>
Hi
ReplyDeleteI am getting error wile installing frameowrk.
Errors! No Resource App's Found within "2-In" Folders
is there is any need to set environmental variables path?
ReplyDeletebcoz it gives me error when type "dex2jar classes.dex"
not recognized command.plz help.
Set java path.
Deletemd mohsin can help me?? when i copy the path directory to the cmd and enter cannot work
ReplyDeleteif you want my friend may i send to you the apk?
ReplyDeleteyou have to do yourself. I can help you if you got any error.
Deleteupdate to apkinstall link????
ReplyDeleteI will update tomorrow. If you still not get proper solution than you can contact me at info@coders-hub.com
Deleteplease update the apktool link
ReplyDeleteI will update tomorrow. If you still not get proper solution than you can contact me at info@coders-hub.com
Delete