I accidentally erased my project from Eclipse, and all I have left is the APK file which I transferred to my phone. Is there a way to reverse the process of exporting an application to the .apk file, so I can get my project back?
This is not my story. But you will find similar question on many forums. So in this blog we gonna use some tools to get our file back and understand ethically what’s inside APK.
What are APK Files?
APK files are analogous to other software packages such as APPX in Microsoft Windows or Deb packages inDebian-based operating systems like Ubuntu. To make an APK file, a program for Android is first compiled, and then all of its parts are packaged into one file. An APK file contains all of that program’s code (such as .dex files), resources, assets, certificates, and manifest file.
So, If APK file contain resources, manifest and dex files. How to get them back?
Here are the steps that let you help in get back your files.
- Make a new folder and copy over the .apk file that you want to decode.
- Now rename the extension of this .apk file to .zip (e.g. rename from app-release.apk to app-release.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, Now extract this .zip file in the same folder (reverse_engg).
- Download dex2jar and extract it to the same folder (or reverse_engg).
- Move the classes.dex file into the dex2jar folder.
- Now open command prompt and change directory to that folder (or reverse_engg). Then write
d2j-dex2jar classes.dex
(for mac terminal or Ubuntu write./d2j-dex2jar.sh classes.dex
) and press enter. You now have the classes.dex.dex2jar file in the same folder.
- Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.
- Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.
- Put in the .apk file which you want to decode
- Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder
- Download framework-res.apk and put it in the same folder (Not all apk file need this file, but it doesn’t hurt)
- Open a command window
- Navigate to the root directory of APKtool and type the following command:
apktool if framework-res.apk
apktool d myApp.apk
(where myApp.apk denotes the filename that you want to decode)
Hopefully you had enjoyed doing the reverse engg. and solved your problem.