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)
Initial decompression

  1. Extract the contents to a folder in the root of your drive called “AndroidRecover"
  2. Drop your .APK file into this directory
  3. Open CMD prompt and type the following
  4. C:\AndroidRecover\apktool d YourAppName.APK"
  5. You should now see a list of all your source files on the screen (this should slowly start to make you feel better)
  6. Next type the following
  7. C:\ AndroidRecover\apktool if YourAppName.APK"
  8. You should now see the following:
  9. I Framework installed to: ……
  10. Then type:
  11. C:\AndroidRecover\apktool d YourAppName.APK MySourceCode"
  12. Your .APK will now be decompiled into a sub folder called “MySourceCode"
  13. 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

  1. 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)
  2. Extract the classes.dex file and put this into the following location
  3. “C:\ AndroidRecover\ConvertDex
  4. Run the following command from CMD prompt
  5. C:\ AndroidRecover\ConvertDex\dex2jar classes.dex
  6. In the “C:\ AndroidRecover\ConvertDex\" folder you will now have a file called classes_dex2jar.jar
  7. Run jd-gui.exe from “C:\ AndroidRecover" and open the new classes_dex2jar.jar file
  8. You will now be presented with your .java source code you thought you had lost.
  9. 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.

Cheers

C.