Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

android - 有没有办法从APK文件中获取源代码?(Is there a way to get the 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.

(我的笔记本电脑上的硬盘驱动器刚刚崩溃,并且丢失了过去两个月来我一直在使用的应用程序的所有源代码。)

All I have is the APK file that is stored in my email from when I sent it to a friend.

(我所拥有的就是APK文件,该文件存储在我发送给朋友时的电子邮件中。)

Is there any way to extract my source code from this APK file?

(有什么办法可以从这个APK文件中提取我的源代码?)

  ask by Frank Bozzo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Simple way: use online tool http://www.javadecompilers.com/apk , upload apk and get source code.

(简单方法:使用在线工具http://www.javadecompilers.com/apk ,上传apk并获取源代码。)


Procedure for decoding .apk files, step-by-step method:

(.apk文件解码过程,分步方法:)

Step 1: (第1步:)

  1. Make a new folder and copy over the .apk file that you want to decode.

    (新建一个文件夹,然后复制要解码的.apk文件。)

  2. Now rename the extension of this .apk file to .zip (eg rename from filename.apk to filename.zip) and save it.

    (现在,将此.apk文件的扩展名重命名为.zip(例如,从filename.apk重命名为filename.zip)并保存。)

    Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.

    (现在,您可以访问classes.dex文件等。在此阶段,您可以看到可绘制对象,但看不到xml和java文件,因此继续。)

Step 2: (第2步:)

  1. Now extract this .zip file in the same folder (or NEW FOLDER).

    (现在,将此.zip文件解压缩到同一文件夹(或NEW FOLDER)中。)

  2. Download dex2jar and extract it to the same folder (or NEW FOLDER).

    (下载dex2jar并将其压缩到同一文件夹(或NEW FOLDER)。)

  3. Move the classes.dex file into the dex2jar folder.

    (将classes.dex文件移动到dex2jar文件夹中。)

  4. Now open command prompt and change directory to that folder (or NEW FOLDER).

    (现在打开命令提示符,并将目录更改为该文件夹(或NEW FOLDER)。)

    Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex ) and press enter.

    (然后编写d2j-dex2jar classes.dex (对于Mac终端或ubuntu,请编写./d2j-dex2jar.sh classes.dex )并按Enter。)

    You now have the classes.dex.dex2jar file in the same folder.

    (现在,您在同一文件夹中有classes.dex.dex2jar文件。)

  5. 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.

    (下载java decompiler ,双击jd-gui,单击打开文件,然后从该文件夹中打开classes.dex.dex2jar文件:现在,您获得了类文件。)

  6. Save all of these class files (In jd-gui, click File -> Save All Sources) by src name.

    (通过src名称保存所有这些类文件(在jd-gui中,单击File-> Save All Sources)。)

    At this stage you get the java source but the .xml files are still unreadable, so continue.

    (在此阶段,您获得了Java源代码,但是.xml文件仍然不可读,因此继续。)

Step 3: (第三步:)

Now open another new folder

(现在打开另一个新文件夹)

  1. Put in the .apk file which you want to decode

    (放入您要解码的.apk文件)

  2. 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

    (下载最新版本的apktool apktool安装窗口 (均可从同一链接下载)并将它们放置在同一文件夹中)

  3. Open a command window

    (打开命令窗口)

  4. Now run command like apktool if framework-res.apk (if you don't have it get it here )and next

    (现在, apktool if framework-res.apk运行apktool if framework-res.apk命令(如果没有,请在此处获取 ),然后运行下一步)

  5. apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)

    (apktool d myApp.apk (其中myApp.apk表示要解码的文件名))

now you get a file folder in that folder and can easily read the apk's xml files.

(现在,您在该文件夹中获得一个文件夹,并且可以轻松读取apk的xml文件。)

Step 4: (第四步:)

It's not any step, just copy contents of both folders(in this case, both new folders) to the single one

(这不是任何步骤,只需将两个文件夹(在本例中为两个新文件夹)的内容复制到一个文件夹中)

and enjoy the source code...

(并享受源代码...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...