2018.1.16我看到了别人的一个布局很棒并且自己写的app也有修改页面的需求,于是想看下别人写的布局源码。搜了下发现apktools能做到便下了一个,但没有预料中的顺利。
首先到网络上(http://www.uzzf.com/soft/42697.html)下载一个安装包解压,然后并把要解压的apk文件(我的apk文件名为test)放入apktool的路径下
使用cmd进行如下操作
C:\Users\Jun>f: //进入f盘 F:\>cd F:\apk反编译\apk2java\apktool1.4.1 //进入解压好的路径(注意:每个人的路径都不相同) F:\apk反编译\apk2java\apktool1.4.1>apktool.bat d -f test.apk test //进行反编译 (最后一个test的意思是建一个test的文件夹并把内容放入其中)
以下就是问题所在了:
1、下载的apktools版本过久 解析不了该apk文件
报错如下:
F:\apk反编译\apk2java\apktool1.4.1>apktool.bat d -f test.apk test` I: Baksmaling...` testI: Loading resource table...` Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file` at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:55) • at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:315) • at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:50) • at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:43) • at brut.androlib.Androlib.getResTable(Androlib.java:44) • at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:148) • at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98) • at brut.apktool.Main.cmdDecode(Main.java:128) • at brut.apktool.Main.main(Main.java:65) • Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000 • at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48) • at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:45) • at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:97) • at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:82) • at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48) • `... 8 more`
我们可以从文件夹名字可以看到这个apktools版本为1.4.1版本的,而目前最新的版本是
2.3.1了
解决方法:
到官网https://ibotpeaches.github.io/Apktool/下载最新jar替代掉旧版本
2、版本是最新的版本,但使用的方法已经过时
F:\apk反编译\apk2java\apktool1.4.1>apktool d -r -s test.apk test 报错如下: Input file (test) was not found or was not readable.
这个方法好像到2.0版本的时候已经过时了
解决方法:到apktools官网即可查看最新的使用方法:
$ apktool d test.apk I: Using Apktool 2.2.1 on test.apk I: Loading resource table... I: Decoding AndroidManifest.xml with resources... I: Loading resource table from file: 1.apk I: Regular manifest package... I: Decoding file-resources... I: Decoding values */* XMLs... I: Baksmaling classes.dex... I: Copying assets and libs... I: Copying unknown files... I: Copying original files... $ apktool b test I: Using Apktool 2.2.1 on test I: Checking whether sources has changed... I: Smaling smali folder into classes.dex... I: Checking whether resources has changed... I: Building resources... I: Building apk file... I: Copying unknown files/dir...
我们只需用到第一行命令
F:\apk反编译\apk2java\apktool1.4.1>apktool d test.apk 命令即可
这个时候会显示
F:\apk反编译\apk2java\apktool1.4.1>apktool d test.apk I: Using Apktool 2.3.1 on test.apk I: Loading resource table... I: Decoding AndroidManifest.xml with resources... S: WARNING: Could not write to (C:\Users\Jun\AppData\Local\apktool\framework), using C:\Users\Jun\AppData\Local\Temp\ instead... S: Please be aware this is a volatile directory and frameworks could go missing, please utilize --frame-path if the default storage directory is unavailable I: Loading resource table from file: C:\Users\Jun\AppData\Local\Temp\1.apk I: Regular manifest package... I: Decoding file-resources... I: Decoding values */* XMLs... I: Baksmaling classes.dex...
表明你反编译成功啦!
反编译的内容就会出现在你对应文件夹上里了
如果出现
F:\apk反编译\apk2java\apktool1.4.1>apktool d test.apk Destination directory (F:\apk反编译\apk2java\apktool1.4.1\test) already exists. Use -f switch if you want to overwrite it.
我们只要把原来的test文件夹删掉就可以了,再跑一遍就行啦!
(遗憾的是,本人使用as查看资源文件后发现该app的布局使用了自定义view,这说明我还得去反编译别人的代码文件。。。如有错误的地方,欢迎指出)
嫌麻烦的可以去下载本人改好的apktool: