aapt的设置和简单使用

1、aapt工具介绍

aapt即Android Asset Packaging Tool,在SDK的build-tools目录下。该工具可以查看,创建, 更新ZIP格式的文档附件(zip, jar, apk)。也可将资源文件编译成二进制文件,尽管你可能没有直接使用过aapt工具,但是build scripts和IDE插件会使用这个工具打包apk文件构成一个Android 应用程序。在使用aapt之前需要在环境变量里面配置SDK-tools路径,或者是路径+aapt的方式进入aapt。

2、Mac上环境变量配置

1)touch ~/.bash_profile

2)open -t ~/.bash_profile

修改环境变量

Example:

export PATH=${PATH}:/Users/sunshanshan/Library/Android/sdk/build-tools/23.0.0

注意:不同的电脑最后路径可能不一样,需要自己确定最后一个文件是否是23.0.0,从该路径下找到aapt(然后执行pwd指令获取当前路径即可)

环境变量添加完成

 

3)source  ~/.bash_profile

修改文件后执行生效操作

4)echo $PATH

查看环境变量是否生效

5)直接在终端中输入aapt,显示如下表示已经成功添加环境变量

 

3、aapt的常用解析apk指令

 aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]

   badging          Print the label and icon for the app declared in APK.

   permissions      Print the permissions from the APK.

   resources        Print the resource table from the APK.

   configurations   Print the configurations in the APK.

   xmltree          Print the compiled xmls in the given assets.

   xmlstrings       Print the strings of the given compiled xml assets.

 

 

Example:aapt -dump <apk文件路径> 这条指令就是查看QQ.apk这个Android安装包的资源列表,里面包括了版本号等基本信息

3.2 aapt l -v <apk文件路径>

  • Length:原始文件的长度

  • Date:日期

  • Time:时间

  • Name:名称

  • Method:压缩方法,Deflate及Stored两种,即该Zip目录采用的算法是压缩模式还是存储模式;可以看出resources.arsc、*.png采用压缩模式,而其它采用压缩模式。

  • Ratio:压缩率

  • Size:这个是压缩省掉的大小,即如果压缩率是xx%。那Size是原始长度*(1-xx%)

  • CRC-32:循环冗余校验。这个计算是有特定的算法的。

  • offset:zipfile中的偏移量



 

posted @ 2018-08-28 15:52  sunshanshan  阅读(3899)  评论(0编辑  收藏  举报