AAPT使用小结

来源:互联网 发布:美豆数据 编辑:程序博客网 时间:2024/06/01 10:04

汇总之前查阅的AAPT相关知识。

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


AAPT的常用命令

1. 列出apk包的内容

aapt l[ist] [-v] [-a] file.{zip,jar,apk}
-v 以table形式列出来
-a 详细列出内容
例如:aapt l <你的apk文件>,这个命令就是查看apk内容

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

例如:aapt d permissions <apk文件>, 这个就是显示这个apk所具有的权限

3. 编译android资源

aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] /       [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] /       [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] /       [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] /       [--rename-manifest-package PACKAGE] /       [--rename-instrumentation-target-package PACKAGE] /       [--utf16] [--auto-add-overlay] /       [--max-res-version VAL] /       [-I base-package [-I base-package ...]] /       [-A asset-source-dir]  [-G class-list-file] [-P public-definitions-file] /       [-S resource-sources [-S resource-sources ...]]         [-F apk-file] [-J R-file-dir] /       [--product product1,product2,...] /       [raw-files-dir [raw-files-dir] ...]

这个比较复杂,只解释几个关键参数。

-f 如果编译出来的文件已经存在,强制覆盖。
-m 使生成的包的目录放在-J参数指定的目录。
-J 指定生成的R.java的输出目录
-S res文件夹路径
-A assert文件夹的路径
-M AndroidManifest.xml的路径
-I 某个版本平台的android.jar的路径
-F 具体指定apk文件的输出

例如:

1). 将工程的资源编译R.java文件

 aapt package -m -J <R.java目录> -S <res目录> -I <android.jar目录>  -M <AndroidManifest.xml目录>

2). 将工程的资源编译编译到一个包里

 aapt package -f  -S <res目录> -I <android.jar目录> -A<assert目录>  -M <AndroidManifest.xml目录> -F <输出的包目录>
Package the android resources.It will read assets and resources that are supplied with the -M -A -S or raw-files-dir arguments.The -J -P -F and -R options control with files are output.

aapt对应APP包的相关信息,如DEBUG模式,最小版本,目标SDK版本APP名称与版本以及编码等信息的输出.

指定移出来自归档的某个文件 Delete specified files from Zip-cpmpatible archive.

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

指定某归档进行添加文件 Add specified files to Zip-compatible archive.

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

对PNG格式处理并进行存储然后对其结果输出到文件夹中 Do PNG preprocessing and store the results in output folder.

 aapt c[runch] [-v] -S resource-sources ... -C output-folder ... 

打印应用程序的版本:

 aapt v[ersion]  Print program version.

打印androdi指定l列出来的数据,如resource与manifest的资源数据 Modifiers:

 -a print Android-specific data (resources,manifest) when listing

指定配置文件相关参数:

 -c specify which configurations to include.The default is all configurations.The value of the parameter should be a comma separated list of configuration value.Locales should be specified as either a language or language-region pair.Some examples:
 en port,en port,land,en_US

If you put the special locale,zz_ZZ on the list,it will perform pseudolocalozation on the default locale,modifying all of the strings so you can look for strings that missed the internationalization process. For example:

 port,land,zz_ZZ -d one or more device assets to include,separated by commas(一个或多个资源文件)
 -f force overwite of existing files(强制覆写已经存在的文件) -g specify a pixel tolerance to force images to grayscale,default 0 -j specify a jar or zip file containing classes to include -k junk path of file(s) added -m make package directories under location specified by -J -o create overlay package (ie only resource; expects <overlay-package> in manifest) -u upate existing package (add new,replace older,remove deleted files) -v verbose output -x create extending (non-application) resource IDs -z require localization of resource attributes marked with localization=suggested" -A additional directory in which to find raw asset files -G A file to output proguard options into. -F specify the apk file to output -I add an existing package to base include set -J specify where to output R.java resurce constant definitions -M specify full path to AndroidManifest.xml to incliude in zip -P specify where to output public resource definitions -S directory in which to find resources.Multiple directories will be scanned

and the first match found (left to right) will take precedence.

 -0 specifies an additional extension for which such files will not be stored compressed int the .apk.An empty string means to not compress any files at all.

4.  打包好的apk中移除文件

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

例如:aapt r <你的apk文件> AndroidManifest.xml, 这个就是将apk中的AndroidManifest移除掉

5. 添加文件到打包好的apk中

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

例如:aapt a <你的apk文件> <要添加的文件路径>, 这个就是将文件添加到打包好的apk文件中

6.  显示aapt的版本

 aapt v[ersion]

例如:aapt v, 就是打印这个结果 Android Asset Packaging Tool, v0.2

aapt工具也支持很多子命令。

 aapt l[ist]:列出资源压缩包里的内容。 aapt d[ump]:查看APK包内指定的内容。 aapt p[ackage]:打包生成资源压缩包。 aapt r[emove]:从压缩包中删除指定文件。 aapt a[dd]:向压缩包中添加指定文件。 aapt v[ersion]:打印aapt的版本。

示例:

 aapt -A <附件资源路径> -S <资源路径> -M <Android应用清单文件> -I <额外添加的包> And -F 目标文件路径
0 0
原创粉丝点击