Vous êtes sur la page 1sur 3

1/28/13

Android: Getting source code from an APK file - Stack Overflow

Android: Getting source code from an APK file

The hard drive on my laptop just crashed and I lost all the source code for an app that I have been working on for the past two months (I know I am an idiot for not backing it up) All I have is the APK file that is stored in my email from when I sent it to a friend. My question is: Is there any way to extract my source code from this APK file? I realize that is is most likely a shot in the dark... but I am really desperate. I have read about tools like smali and apktool... could these be of help?
android android-resources

edited Jan 15 at 14:08 Avatarus 25 5 feedback

asked Aug 29 '10 at 3:40 Frank Bozzo 492 3 6 15

5 Answers
Procedure to decoding .apk files ---step wise method-->

Step 1:
Make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg:rename from filename.apk to filename.apk.zip) and save it..now you get classes.dex files etc...at this stage you are able to see drawable but not xml and java file...so cont...

Step 2:
Now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now dowmload dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (in this case NEW FOLDER).....now open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write d e x 2 j a rc l a s s e s . d e x and press enter.....now you get classes.dex.dex2jar file in the same folder......now download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file then open classes.dex.dex2jar 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)..by src name....at this stage you get source...but xml files are still unreadable...so cont...

Step 3:
Now open another new folder and put these files 1. put .apk file which you want to decode 2. download apktool v1.x AND apktool install window using google and put in the same folder 3. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file) 4. Open a command window 5. Navigate to the root directory of APKtool and type the following command: a p k t o o li f f r a m e w o r k r e s . a p k 6. a p k t o o ld" f n a m e " . a p k ("fname" denotes filename which you want to decode)
stackoverflow.com/questions/3593420/android-getting-source-code-from-an-apk-file 1/3

1/28/13

Android: Getting source code from an APK file - Stack Overflow

now you get a file folder in that folder and now you can easily read xml files also.

Step 4:
It's not any step just copy contents of both folder(in this case both new folder)to the single one and now enjoy with source code...
edited Aug 5 '12 at 17:33 Shawn Lien 60 7 thaks emulator .. prankul garg May 21 '11 at 11:32 Thanks a lot but i have a problem after doing 3rd step all files comes n the smali format how can i read it. Android Developer Jul 19 '11 at 9:42 answered May 21 '11 at 11:20 prankul garg 1,996 1 4 2

2 1 1

@prankulgarg ,In point 5 of step 3 i am getting following error: Unable to access jarfile E:\apktojava\testt\\apktool.jar user775 Jan 30 '12 at 7:00 So where does one get the f r a m e w o r k r e s . a p k file.. Am unable to find a trusted copy :| SalmanPK Jul 23 '12 at 14:48 @SteveDesai follow this souldevteam.net/blog/2012/01/27/ avirk Dec 1 '12 at 16:26

show 10 more comments feedback

While you may be able to get an APK decompiler somewhere, you will likely hit one big issue: its not going to return the code you wrote. Its going to return whatever the compiler inlined, with variables given random names, as well as functions given random names. It very well may take significantly more time to try to decompile and restore into the code you had, then it will be to start over. Sadly, things like this have killed many projects. For the future, I highly recommend learning a Version Control System, like CVS, SVN, git, etc... and how to back it up.
answered Aug 29 '10 at 3:58 Ryan Gooler 527 2 11

2 1

A service like Dropbox will also help. fiXedd Aug 29 '10 at 8:19 +1 for dropbox. Best thing ever Falmarri Aug 29 '10 at 11:12 Funny, I actually had the Dropbox idea a while ago but didn't do it. And now, I'm googling "extract source code from apk." Guess who's upset with themselves. Snailer Jun 21 '11 at 1:11 Burned disk :[ I'have losted many projects, everybody has own way of the Cross... Lumma Apr 4 '12 at 12:11

feedback

apktool will work. You don't even need to know the keystore to extract the source code (which is a bit scary). The main downside is that the source is presented in Smali format instead of Java. Other files such as the icon and main.xml come through perfectly fine though and it may be worth your time to at least recover those. Ultimately, you will most likely need to re-write your Java code from scratch. You can find apktool here. Simply just download apktool and the appropriate helper (for Windows, Linux, or Mac OS). I recommend using a tool such as 7-zip to unpack them.
answered Aug 29 '10 at 4:02 Ryan Berger 3,071 2 17 35

stackoverflow.com/questions/3593420/android-getting-source-code-from-an-apk-file

2/3

1/28/13
feedback

Android: Getting source code from an APK file - Stack Overflow

apktool is the best thing you can try. I have saved some xml with it, but honestly I don't know how it will work with the .java code. I would recommend you to have a code repository even if your are the only coder. I've been using Project Locker for my own projects. It gives you free svn and git repos.
answered Aug 29 '10 at 12:17 Macarse 24.5k 11 66 136

feedback

These two articles describe how to combine the use of apktool and dex2jar to take an APK file and create an Eclipse project that can build and run it. http://blog.inyourbits.com/2012/11/extending-existing-android-applications.html http://blog.inyourbits.com/2012/12/extending-existing-android-applications.html Basically you: 1. 2. 3. 4. 5. 6. 7. 8. Use apktool to get the resource files out of the apk Use dex2jar to get a jar file that contains the classes in a format that Eclipse will like. Create an Eclipse project point it at the resource files and the new jar file Open the jar file with a zip utility and delete the existing resources Open the jar file with JDGui to view the source code Take whatever source code you need from JDGui, stick it in a class inside Eclipse and modify it Delete that class from the jar file (so you don't have the same class defined multiple times) Run it.

answered Dec 6 '12 at 1:38 Tom Hennen 729 3 8 18 feedback

protected by Community Jun 2 '11 at 5:18


This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged
android-resources or ask your own question.

android

stackoverflow.com/questions/3593420/android-getting-source-code-from-an-apk-file

3/3

Vous aimerez peut-être aussi