您的位置:首页 > 移动开发 > Android开发

41.Android aapt工具

2015-11-28 15:52 525 查看

41.Android aapt工具

Android aapt工具
aapt 介绍

aapt 环境配置

aapt list

aapt dump

aapt package

其他命令

aapt 介绍

可参考官方文档: http://www.androidcn.net/wiki/index.php/Reference/aapt

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.

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.

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

Linux or Mac OS X:

./aapt

Windows:

aapt.exe

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

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

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

Linux or Mac OS X:

./aapt

Windows:

aapt.exe

aapt 环境配置

aapt工具位于:
sdk/buid-tools/android-[version]/aapt


Windows环境的话,可以直接在环境变量里配置一个PATH,指定到
sdk/buid-tools/android-[version]
即可。

Mac环境的话,我用的是Oh My Zsh,所以直接
vi ~/.zshrc
,以下是我配置:

# Add Android build-tools AAPT variable
AAPT_HOME=/Users/CaMnter/Android/adt-bundle-mac-x86_64-20140702/sdk/build-tools/23.0.2
export AAPT_HOME
export PATH=$PATH:$AAPT_HOME


然后在命令行下输入:aapt。



可以看到 aapt 的所有命令,和命令对应有哪些参数。

aapt list

aapt l[ist] [-v] [-a] file.{zip,jar,apk}

List contents of Zip-compatible archive.

查看apk目录:

aapt l *.apk




查看apk目录,以表格形式输出:

aapt l -v *.apk


Method : 压缩形式 , Deflate 或 Stored 。

Ratio : 压缩率

CRC-32 : 循环冗余校验



详细查看apk目录:

aapt l -a *.apk




aapt dump

aapt d[ump] [–values] [–include-meta-data] WHAT file.{apk} [asset [asset …]]

strings Print the contents of the resource table string pool in the APK.

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.

查看apk:package、sdkVersion、targetSdkVersion、application-label、launchable-activity、feature-group等信息:

aapt d badging *.apk




查看apk权限:

aapt d permissions *.apk




查看apk资源:

aapt d resources *.apk




查看apk配置:

aapt d configurations *.apk




查看xml的树形结构:

aapt d xmltree *.apk res/*.xml




查看xml中所有的string:

aapt d xmlstrings *.apk res/*.xml




查看信息后输出文件:

aapt d ... >*.txt




查看输出:



aapt package

生成R.java:

先定位到项目目录下

aapt package -m -J ~/temp/ -S app/src/main/res -I /Users/CaMnter/Android/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-23/android.jar -M /Users/CaMnter/GitHub/AndroidLife/app/src/main/AndroidManifest.xml


-J ~/temp/ : 设置输出目录

-S app/src/main/res: 资源文件res目录

-I /Users/CaMnter/Android/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-23/android.jar: android.jar路径

**-M /Users/CaMnter/GitHub/AndroidLife/app/src/main/AndroidManifest.xml:**AndroidManifest绝对路径

生成资源文件

还是先定位到项目目录下

aapt package -f -M /Users/CaMnter/GitHub/AndroidLife/app/src/main/AndroidManifest.xml -S app/src/main/res -A app/src/main/assets  -I /Users/CaMnter/Android/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-23/android.jar -F ~/log/resouces


**-M /Users/CaMnter/GitHub/AndroidLife/app/src/main/AndroidManifest.xml:**AndroidManifest绝对路径

-S app/src/main/res: 资源文件res目录

-A app/src/main/assets: assets目录

-I /Users/CaMnter/Android/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-23/android.jar: android.jar路径

-F ~/log/resouces: resouces.arsc存放路径

其他命令

输出aapt版本

aapt v[ersion]

Print program version.

删除apk中指定文件

aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 …]

Delete specified files from Zip-compatible archive.

添加指定文件到apk中

aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 …]

Add specified files to Zip-compatible archive.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息