我的笔记本电脑上的硬盘刚刚崩溃了,我失去了过去两个月一直在开发的应用程序的所有源代码。我手头只有一份存储在邮件中的APK文件,当时是给朋友发送的。
有没有办法从这个APK文件中提取我的源代码呢?
我的笔记本电脑上的硬盘刚刚崩溃了,我失去了过去两个月一直在开发的应用程序的所有源代码。我手头只有一份存储在邮件中的APK文件,当时是给朋友发送的。
有没有办法从这个APK文件中提取我的源代码呢?
使用这里给出的被接受的答案。
你不需要使用被接受的答案中提供的方法,因为我觉得它很复杂。
相反,我所做的是将APK文件转换为ZIP并进行解压。解压后,我得到了一个名为res的文件夹:
我刚刚打开它,发现了很多文件夹。关于布局,你需要找到名为layout
的文件夹,而不是其他类似layout-land之类的文件夹。其他资源如drawable、menu等也可以用同样的方法处理。我已经为了让dex2jar在Fedora 31笔记本电脑上对一个无法工作的apk进行工作而疯狂了几天。这个Python 3脚本在几分钟内解决了问题,并安装jd-gui使类文件可读。
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
然后只需打开您的类文件!
Android应用程序的APK文件可以使用以下任何方法进行反编译:
javac -decompile
,这将符合SO准则。在我看来,答案是“离题的”,而不是问题本身。 - SwiftArchitect