现在的位置: 首页 > 综合 > 正文

android aapt使用小结

2018年04月16日 ⁄ 综合 ⁄ 共 2803字 ⁄ 字号 评论关闭

aapt stands for Android Asset Packaging Tool and is included in the tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives
(zip, jar, apk). It can also compile resources into binary assets.

aapt即Android Asset Packaging Tool , 在SDK的tools/目录下. 该工具可以查看, 创建, 更新ZIP格式的文档附件(zip, jar, apk). 也可将资源文件编译成二进制文件.

Though you probably won't often use aapt directly, build scripts and IDE plugins can utilize this tool to package the apk file that constitutes an Android application.

尽管你可能没有直接使用过aapt工具, 但是build scripts和IDE插件会使用这个工具打包apk文件构成一个Android 应用程序.

For more usage details, open a terminal, go to the tools/ directory, and run the command:

获取更多的实用信息, 请打开终端控制台, 到tools/目录下, 执行命令:

Linux or Mac OS X:

  ./aapt

Windows:

aapt.exe

 

 

 

 

本文小结了一下该工具的用法。
1.  aapt l[ist] [-v] [-a] file.{zip,jar,apk}
   List contents of Zip-compatible archive.
1.1 列出压缩文件目录
aapt l <file_path.apk>
参数:
-v:会以table的形式输出目录,table的表目有:Length、Method、Size、Ratio、Date、Time、CRC-32、Name。
其中Method表示压缩形式,有:Deflate及Stored两种,即该Zip目录采用的算法是压缩模式还是存储模式;可以看出resources.arsc、*.png采用压缩模式,而其它采用压缩模式。
Ratio表示压缩率。CRC-32未明其意,Sodino盼指教。

-a:会详细输出所有目录的内容。
效果图:aapt_list.JPG
 list

2. 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.

2.1 查看apk包的packageName、versionCode、applicationLabel、launcherActivity、permission等各种详细信息
aapt dump badging <file_path.apk>
效果图:aapt_dump_badging.JPG
 badging

2.2 查看权限
aapt dump permissions <file_path.apk>
效果图:aapt_dump_permissions.JPG

 permission

2.3 查看资源列表
aapt dump resources <file_path.apk>
一般都会输出很多的信息,如要全部查看,请用下面这两句:
aapt dump resources <file_path.apk>   > sodino.txt
sodino.txt
这样会把所有的信息通过重定向符">"输出到sodino.txt文件中,然后再打开该文件即可查看。

2.4 查看apk配置信息
aapt dump configurations <file_path.apk>

2.5 查看指定apk的指定xml文件。
aapt dump xmltree <file_path.apk> res/***.xml
以树形结构输出的xml信息。
aapt dump xmlstrings <file_path.apk> res/***.xml
输出xml文件中所有的字符串信息。
效果图:aapt_dump_xmltree.JPG

 xmltree

3
由于此处代码量比较大,本人写成批处理形式了。

使用aapt生成R.java
rem 测试的工程目录下必须得有gen文件夹,否则会提示:Unable to open class file R.java:No such file or directory
%aapt% package -f -m -J %GEN% -S %RES% -I %ANDROID_JAR% -M %ANDROID_MANIFEST_XML%

使用aapt生成资源包文件
%aapt% package -f -M %ANDROID_MANIFEST_XML% -S %RES% -A %ASSETS% -I %ANDROID_JAR% -F %RESOURCE%

%GEN%:存放的R.java文件夹路径。
%RES%:res文件夹路径。
%ANDROID_JAR%:引用的android.jar路径。
%ANDROID_MANIFEST_XML%:工程AndroidManifest.xml绝对路径。
%ASSETS%:asset文件夹路径。
%RESOURCE%:生成的resouces.arsc存放路径。

参考:
Android系列之Android 命令行手动编译打包详解
http://blog168.chinaunix.net/space.php?uid=22957718&do=blog&cuid=2322671

 

其余的不解释,直接见效果图:
 aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Delete specified files from Zip-compatible archive.

 aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Add specified files to Zip-compatible archive.

 aapt v[ersion]
   Print program version.
效果图:aapt_r_a_v.JPG  

r_a_v

 

抱歉!评论已关闭.