我笔记本电脑上的硬盘刚刚崩溃,我丢失了过去两个月一直在开发的应用程序的所有源代码。我只有一个APK文件,它存储在我发给朋友的电子邮件中。

有没有办法从这个APK文件中提取我的源代码?


当前回答

可能是最容易看到的来源:

在Android studio 2.3中,构建->分析APK->选择要反编译的APK。你会看到它的源代码。

参考链接:https://medium.com/google-developers/making-the-most-of-the-apk-analyzer-c066cb871ea2

其他回答

这两篇文章描述了如何结合使用apktool和dex2jar来获取APK文件并创建一个可以构建和运行它的Eclipse项目。

http://blog.inyourbits.com/2012/11/extending-existing-android-applications.htmlhttp://blog.inyourbits.com/2012/12/extending-existing-android-applications.html

基本上你:

使用apktool从apk中获取资源文件使用dex2jar获取一个jar文件,其中包含Eclipse喜欢的格式的类。创建一个Eclipse项目,指向资源文件和新的jar文件使用zip实用程序打开jar文件并删除现有资源使用JDGui打开jar文件以查看源代码从JDGui中获取所需的任何源代码,将其粘贴到Eclipse中的一个类中并进行修改从jar文件中删除该类(这样就不会多次定义相同的类)运行它。

Play Store上还有一个新的应用程序,它可以反编译apk(系统应用程序),并在智能手机上查看源代码。它将文件保存到SD卡中,以便您也可以在计算机上查看。它不需要根或其他东西。

只需安装并享受乐趣。我认为这是反编译应用程序最简单的方法。

对于java文件


使用此处给出的公认答案

对于XML文件


你不必使用公认答案中给出的方法,因为我觉得它很复杂。

我所做的是将APK文件转换为ZIP并解压缩。解压缩后,我得到了一个名为res的文件夹:

我刚打开它,发现了很多文件夹。对于布局,您需要找到名为layout的文件夹,而不是像layout land之类的其他文件夹。同样的事情也可以用其他资源来完成,比如绘图、菜单等。。。

注意:会有很多随机文件不是由您创建的。你可以找到自己制作的文件,然后使用它们!

希望这能帮助到其他人!

单击解决方案(仅限Windows)

在阅读了这篇loooooonnnnngggg帖子后,我决定创建一个自动化的过程,只需单击一下即可反编译APK,

我决定在github上分享:https://github.com/shaybc/apk-decompiler

simply unzip,
copy the apk you want to decompile into "apk-source" folder
and run "go.bat"
find the result in the: "apk-output" folder

就这样,享受吧

几天来,我一直想让dex2jar在一台软呢帽31笔记本电脑上与一台无法工作的apk进行比较,这让我发疯了。这个python3脚本在几分钟内就完成了这个任务,安装jdgui使类文件变得可读。

http://java-decompiler.github.io/

https://github.com/Storyyeller/enjarify

具体来说,下面是我运行的:

# i installed apktool before the rest of the stuff, may not need it but here it is
$> cd /opt
$> sudo mkdir apktool
$> cd apktool/
$> sudo wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool
$> sudo wget https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.4.1.jar
$> sudo mv apktool_2.4.1.jar apktool.jar
$> sudo mv apktool* /usr/bin/
$> sudo chmod a+x /usr/bin/apktool*

# and enjarify
$> cd /opt
$> sudo git clone https://github.com/Storyyeller/enjarify.git
$> cd enjarify/
$> sudo ln -s /opt/enjarify/enjarify.sh /usr/bin/enjarify

# and finally jd-gui
$> cd /opt
$> sudo git clone https://github.com/java-decompiler/jd-gui.git
$> cd jd-gui/
$> sudo ./gradlew build

# I made an alias to kick of the jd-gui with short commandline rather than long java -jar blahblahblah :)
$> echo "jd-gui='java -jar /opt/jd-gui/build/launch4j/lib/jd-gui-1.6.6.jar'" >> ~/.bashrc

现在应该可以使用以下方法获取类文件:

$> enjarify yourapkfile.apk

要启动jd-gui:

$> jd-gui

那就打开你的课堂文件吧!