博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android aapt使用小结
阅读量:3521 次
发布时间:2019-05-20

本文共 2980 字,大约阅读时间需要 9 分钟。

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 命令行手动编译打包详解

 

其余的不解释,直接见效果图:

 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

 

转载地址:http://afhqj.baihongyu.com/

你可能感兴趣的文章
设计模式七大原则
查看>>
手写 | spring事务
查看>>
AndroidStudio Gradle手动下载
查看>>
SpringBoot入门(二)场景启动器
查看>>
SpringBoot入门--自动配置
查看>>
springboot读取配置文件 例:读取配置文件的优先顺序;在主配置文件中激活其他配置文件;加载非主配置文件
查看>>
自动配置原理
查看>>
TCP协议
查看>>
关于Linux系统使用遇到的问题-1:vi 打开只读(readonly)文件如何退出保存?
查看>>
redis 持久化详解,RDB和AOF是什么?他们优缺点是什么?运行流程是什么?
查看>>
spring注解版(一)
查看>>
SpringBoot中访问控制层(controller)得不到Json数据
查看>>
react项目报出警告Warning: Cannot update during an existing state transition (such as within `render`).
查看>>
BFC(Block Formatting Context)
查看>>
什么是作用域,什么是闭包,什么是作用域链
查看>>
惰性求值,面向对象
查看>>
lodash源码分析之baseSlice()函数
查看>>
数据结构之列表
查看>>
发布/订阅模式 vs 观察者模式
查看>>
es5中的arguments对象
查看>>