Wednesday, 9 May 2012

Android - How to extract resources and source code from apk

 Hi Guys,

This is for the people who has apk file and lost the source code unfortunately and who wants some initial push to write great apps( i mean by copying :P ).

 First download the apk file you want to decode into a separate folder.

Step 1: How to Get images and Icons :
  •  add extension ".zip" to your .apk file.                                                                                               
          Ex:  Myexample.apk   rename to  Myexample.apk.zip
  • Unzip the file, then it will create a folder with all resources folders , AndroidManifest file and "classes.dex" file which contains source code.
Now,  you have all the images and all xml files. Problem is all xml files are in unreadble format.If you just need images this step is enough. If you want images and readable xml also then follow following approach.


Step 2 : Decode Resources and Xml files :

Open another new folder and put following  files in that
  • put .apk file which you want to decode
  • download apktool XX.tar and apktool-install-windows XXX.tar and extract both in same folder 
          http://code.google.com/p/android-apktool/downloads/list                                               

         apktool xx.tar will give you apktool.jar                                                                         
         apktool-install-XX.tar will give you apktool.bat. This bat file uses apktool.jar so both should be in
         same folder.
  • download framework-res.apk file and put it in same folder.                                      http://www.2shared.com/complete/MIFn5Cuo/framework-res.html 
  • Open command prompt
  • Navigate to the root directory of APKtool.bat and type the following command:     
             >  apktool if   framwork-res.apk                                                                                            
             >  apktool d "fname".apk ("fname" denotes filename which you want to decode)                     
                 Ex: apktool d Myexample.apk



             






Now you get a folder contains resources and readable xml files too. enjoy!!!

Not satisfied, you want source too.. then following steps are for you.

Step 3 : Decoding Source files :

  • First we need to do Step 1. 
  • When you open the folder you can see "classes.dex". We need to De-compile it.
  •  Download dex2jar tool from following link and extract to same folder.
           http://code.google.com/p/dex2jar/
  • Copy classes.dex file into extracted dex2jar folder where you can see "dex2jar.bat"
  • Open command prompt and reach to that folder which contains "dex2jar.bat" and type,
            >  dex2jar classes.dex

         you will get "classes_dex2jar.jar" in same location.That means you converted .dex files .class files.
  •  To get source code we again need to De-compile it. For this download following java De-compiler
           http://java.decompiler.free.fr/?q=jdgui
  • Now double click on jd-gui and click on open file then open  classes_dex2jar.jar  file from that folder...
  • Now you get class file...save all these class file (click on file then click "save all sources" in jd-gui)
  • It will give you "classes_dex2jar.src.zip" it contains all source files.






22 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. @stmt : "Myexample.apk rename to Myexample.apk.zip", already .apk also one type of zip only, so we can directly rename .apk to .zip.

    ReplyDelete
  4. Very Helpful information . Thanks for posting such a good information. I hope same effort further :)

    ReplyDelete
  5. Strange, when I typed in the "apktool if framwork-res.apk" command I’m getting a message saying “java is not recognized as an internal or external command, operable program, or batch file”

    What did I do wrong?

    ReplyDelete
  6. apk file can't run after compile it again why?

    ReplyDelete
  7. error when decode ...could not decode attr value

    ReplyDelete
  8. GetAPK Market Download Free For Android, Play Store alternative to download free apps using GetAPK Market. Now download unlimited apps for free.
    getapk

    ReplyDelete
  9. Thanks for the information that you have shared in this blog post. I also write on hard disks to help people in making decisions before buying hard disk. please check this link

    ReplyDelete
  10. If you are looking for great apps, download Blackmart APK as it features some of the most amazing apps on its own app store.

    ReplyDelete
  11. Elementary Quantitative Analysis Theory and Practice · Modern Production Among Backward Peoples · Unsolved mysteries of the Arctic · Philadelphia Elibrary

    ReplyDelete
  12. I am getting error while running - apktool if framwork-res.apk
    Error - The system cannot find the path specified.

    ReplyDelete
  13. Thank you very much for upadate very informative blog. Hope you upload more these kin of blogs. Thanks.
    Must watch this

    ReplyDelete
  14. I pernolly like your post. You can involve valueable thing which is really usefull for everyone. Keep it up
    click here

    ReplyDelete
  15. Nice blog !! the issuue that you touch is very informative and great. Keep it up. we are waiting for more apk reviews.
    Visit here

    ReplyDelete
  16. Grand Blog! I should need to thank for the endeavors you have made in shaping this post. I am trusting in a practically identical best work from you later on also.
    Click here

    ReplyDelete
  17. A great degree energizing article thanks for sharing it to each one of us. Looking forward to more information and you have continually intrigued me.
    Best Info

    ReplyDelete
  18. Your posts are really inspiring and useful. I think you deserve better attention on Google search rankings.

    click Here

    ReplyDelete
  19. Your posts are really inspiring and useful. I think you deserve better attention on Google search rankings.
    Tech Reviews

    ReplyDelete
  20. Great site! I really love the way it is simple on my eyes. I am thinking about how I may be told at

    whatever point another post has been made.
    click Here

    ReplyDelete
  21. This site have particular software articles which emits an impression of being a significant and significant for you individual, able software installation.This is the spot you can get helps for any software installation, usage and cracked.
    Must See It

    ReplyDelete