Friday, February 8, 2013

How to get source files from .apk file

How to get source files from .apk file

Android application package file (APK) is the file format used to distribute and install application software and middleware onto Google's Android operating system
We can now get java code from apk files with ease.
Following are steps to get java code from apk file.

Step 1:Renaming .apk file
Rename the .apk file with the extension .zip (suppose the file be "android.apk" then after renaming it becomes "android.apk.zip")
Step 2:Get the java files from apk
2.1 Now extract the renamed zip file(android.apk.zip) in specific folder, supposed that folder     
       name is "androidFolder".
2.2 Now Download dex2jar and extract that zip file in folder "androidFolder".
2.3 Now open command prompt and go to the folder path created in previous step and type 
       the command(for example folder path is c:\\androidFolder\dex2jar) 
      "dex2jar ../classes.dex" and press enter.This will generate "classes.dex.dex2jar" file in  
       the same folder.
2.4 Now  Download java decompiler and extract it and start(double click) jd-gui.exe
2.5 Now open jd-gui window browse the generated "classes.dex.dex2jar" file in 
       androidFolder, this will give you all the class files by src name.
2.6 Now from the File menu select "save all sources" this will generate a zip file named 
     "classes_dex2jar.src.zip" consisting of all packages and java files.
2.7 Now extract that zip file (classes_dex2jar.src.zip) and you will get all java files of the 
      application.
Above steps will generate java files.
To get xml files perform following steps.
Step 3:Getting xml files from apk
3.1 Download apktool and install it and extract both files and place it in the same folder (for 
      example "androidXmlFolder").
3.2 Place the .apk file in same folder (i.e androidXmlFolder)
3.3 Now open command prompt and goto the directory where apktool is stored (here 
      "androidXmlFolder") and type the following command "apktool if framework-res.apk" 
      Above command result should be "Framework installed ..."
3.4 Now in command prompt type the command "apktool d filename.apk" (where filename is name of apk file).
3.5 This will generate a folder of name filename in current directory (here androidXmlFolder) where all xml files will be stored in res\layout folder.
Dex to java files



3 comments:

  1. Nice tutorials...!!!

    Thanks.

    ReplyDelete
  2. Hey nice post, thanks for the sharing. These all Apps are
    really awesome. Wordpress is really great App. Via this we can write, edit,
    publish posts easily its very helpful for bloggers

    ReplyDelete
  3. I might try it. Hope this will work out well. Wish me luck!

    ReplyDelete