Lost my data... Able to get my app source from my APK somehow?
My computer broke, and Dell reset the hard drive. This made me lose two months worth of app revisions. It is a fairly simple app, not major in file size, so if it can be decompiled, it shouldn't be too bad. Is there any way to take my APK and output the source code, or at least my MainActivity? Thanks!
You won't be able to get the original source code, but you can use tools to create new source code based on the compiled binary. This is obviously based purely on the binary, so you won't get any of your comments or whitespace and it will be a lot less readable and may not compile or work 100%. But hey, it's better than nothing.
I'd recommend starting with APKTool. That will unpack the manifest and give you smali (Dalvik bytecode assembly) for everything. To recover Java level source code, there are a number of Java decompilers to choose from. I'd recommend giving Enjarify + Procyon a try.
Apart from that, have you tried disk recovery? Depending on what they did to the disk, your data might still be recoverable.
What I use is APKtools, you can extract accurate java source including resources and xml.
To get the source code from APK file, we will need these tools: 1. dex2jar 2. java decompiler 3. apktool 4. apkinstall
Steps to get source:-
Get Java files from APK:- 1. Rename the .apk file into .zip file (example SharedPr.apk into SharedPr.zip).
Extract SharedPr.zip file and copy classes.dex file from extracted folder.
Extract dex2jar.zip and paste classes.dex into dex2jar folder.
Open command prompt and change directory to the dex2jar folder. Then write dex2jar classes.dex and press enter. Now you will get classes.dex.dex2jar file in the same folder.
Now double click on jd-gui(Java decompiler) and click on open file. Then open classes.dex.dex2jar file from that folder. Now you will get class files and save all these class files (click on file then click “save all sources” in jd-gui) by src name.
Get XML files from APK:-
Extract apktool and apkinstall in a folder(Example : New Folder).
Put SharedPr.apk(your apk file) in same folder(ie New Folder).
Open the command prompt and go to the root directory(ie New Folder).
Type command on command prompt: apktool d SharedPr.apk
This will generate a folder of name SharePr in current directory (here New Folder) and all XML files will be in res->layout folder.
上一篇: 从APK文件中获取源代码