简介
我们做web开发的时候,如果想要模仿某一网站的UI,我们可以通过浏览器自带的工具:查看源代码(html),网页中的图片资源以及样式等信息都可以下载到。然后我们用到自己的项目中去,免去了一些UI设计师的麻烦。即便我们重新设计页面,别人的UI也可以作为参考。而在Android开发中,怎么样才能查看别人apk中的资源呢?
1.图片资源
如果想要查看其他apk的图片资源,我们只需要解压apk文件即可。不需要反编译也可以抽取apk中的图片资源
2.xml布局代码等
如果仅仅通过解压,我们获得的xml文件打开时是乱码,没有办法参考。
解决方案:
使用apktool.jar反编译工具
a.下载地址:
http://android-apktool.googlecode.com/files/apktool1.5.2.tar.bz2
b.下载之后,解压之后,就一个apktool.jar文件
c.使用apktool.jar解压apk文件
条件:
1).JDK是必不可少的
2).JDK环境变量配置
使用:
打开windows的cmd或者linux下的终端,将当前目录切换到apktool.jar所在目录
使用提示:
- Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND [...]
- COMMANDs are:
- d[ecode] [OPTS] <file.apk> [<dir>]
- Decode <file.apk> to <dir>.
- OPTS:
- -s, --no-src
- Do not decode sources.
- -r, --no-res
- Do not decode resources.
- -d, --debug
- Decode in debug mode. Check project page for more info.
- -b, --no-debug-info
- Baksmali -- don't write out debug info (.local, .param, .line, etc.)
- -f, --force
- Force delete destination directory.
- -t <tag>, --frame-tag <tag>
- Try to use framework files tagged by <tag>.
- --frame-path <dir>
- Use the specified directory for framework files
- --keep-broken-res
- Use if there was an error and some resources were dropped, e.g.:
- "Invalid config flags detected. Dropping resources", but you
- want to decode them anyway, even with errors. You will have to
- fix them manually before building.
- b[uild] [OPTS] [<app_path>] [<out_file>]
- Build an apk from already decoded application located in <app_path>.
- It will automatically detect, whether files was changed and perform
- needed steps only.
- If you omit <app_path> then current directory will be used.
- If you omit <out_file> then <app_path>/dist/<name_of_original.apk>
- will be used.
- OPTS:
- -f, --force-all
- Skip changes detection and build all files.
- -d, --debug
- Build in debug mode. Check project page for more info.
- -a, --aapt
- Loads aapt from specified location.
- if|install-framework <framework.apk> [<tag>] --frame-path [<location>]
- Install framework file to your system.
- For additional info, see: http://code.google.com/p/android-apktool/
- For smali/baksmali info, see: http://code.google.com/p/smali/
反编译命令:
- > java -jar apktool.jar decode apk文件所在路径
我们以易信为例:
反编译之后,我们就可以在res文件夹下查看易信的xml布局文件