Вы находитесь на странице: 1из 3

11/ 3/ 12

Andr oi : G et t i g sour ce code f r om an APK f i - St ack O ver f l w d n e l o

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

asked Aug 29 '10 at 3:40 Frank Bozzo 352 1 5 15 74% accept rate feedback

4 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 x j r c a s s d x and press enter.....now you get classes.dex.dex2jar file in the e2a lse.e 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 k o l i pto f faeokrsak rmwr-e.p 6. a k o l d " n m " a k ("fname" denotes filename which you want to decode) pto fae.p
st ackover f l w com / quest i ns/ 3593420/ andr oi - get t i g- sour ce- code- f r om - an- apk- f i o . o d n e l 1/ 3

11/ 3/ 12

Andr oi : G et t i g sour ce code f r om an APK f i - St ack O ver f l w d n e l o

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 at 17:33 Shawn Lien 43 6 answered May 21 '11 at 11:20 prankul garg 1,466 1 4 2

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 Thanks a lot but after doing 3rd step i got the .smali format file how can i convert it into xml to see it. Android Developer Jul 19 '11 at 9:46 useless for me unfortunately Jawad Amjad Oct 28 '11 at 13:36 Thanks a lot i was able to do it after i did the exact way you said. thanks again cavallo Dec 14 '11 at 12:31 show 9 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 498 2 10

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 at 12:11

feedback

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 22.5k 9 56 123 feedback

st ackover f l w com / quest i ns/ 3593420/ andr oi - get t i g- sour ce- code- f r om - an- apk- f i o . o d n e l

2/ 3

11/ 3/ 12

Andr oi : G et t i g sour ce code f r om an APK f i - St ack O ver f l w d n e l o

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 2,763 2 15 34

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 your own question.

android or ask

st ackover f l w com / quest i ns/ 3593420/ andr oi - get t i g- sour ce- code- f r om - an- apk- f i o . o d n e l

3/ 3

Вам также может понравиться