Decompress / reverse engineer Android APK file
Recently I lost (due to hard drive failure) all the source code for the Android port of Squares – Fruit Edition (probably the only thing I didn’t have saved in the cloud too).
Anyway, I did however, have the latest .APK file that I used for device testing sat in my dropbox (so close but so far away I thought) – I thought wrong.
After some serious searching I managed to get back everything from the .APK file, but as the tools used for this process were far more advanced than just simply recovering source code, I found a lot of the online tutorials a little long winded and miss-leading.
Well, broken down the best I can, here is my version of events.
First download my pre-packaged toolkit I put together and install JRE 1.7 from Oracle's website (Google it for latest URL)
- Extract the contents to a folder in the root of your drive called “AndroidRecover"
- Drop your .APK file into this directory
- Open CMD prompt and type the following
- “C:\AndroidRecover\apktool d YourAppName.APK"
- You should now see a list of all your source files on the screen (this should slowly start to make you feel better)
- Next type the following
- “C:\ AndroidRecover\apktool if YourAppName.APK"
- You should now see the following:
- I Framework installed to: ……
- Then type:
- “C:\AndroidRecover\apktool d YourAppName.APK MySourceCode"
- Your .APK will now be decompiled into a sub folder called “MySourceCode"
- Look inside the new folder and you should now find your res folder with all your resources along with your AndroidManifest file
Unfortunately your .Java files will be decompressed as .smali files and are no good for importing back into a new project in Eclipse.
Recover .Java files
- Using WinRar (or some other Zip software) select and view your .APK file (yes this is just an archive of many other files for those who did not know)
- Extract the classes.dex file and put this into the following location
- “C:\ AndroidRecover\ConvertDex“
- Run the following command from CMD prompt
- “C:\ AndroidRecover\ConvertDex\dex2jar classes.dex“
- In the “C:\ AndroidRecover\ConvertDex\" folder you will now have a file called classes_dex2jar.jar
- Run jd-gui.exe from “C:\ AndroidRecover" and open the new classes_dex2jar.jar file
- You will now be presented with your .java source code you thought you had lost.
- If you wish simply click, File > Save All Sources and your files will be individually saved (in a zip format) for safe cloud storage
Hope this is useful for anyone who was in the same position as me.
Comments and thoughts welcome.