aapt
Android Asset Packaging Tool
e.g.: $ aapt d resources dest.apk # 查看APK的resources.arsc内容。 验证方法,用一个最简单apk,
$ zip -d apk-debug.apk resources.arsc # 删除根下的resources.arsc.
$ zip -u apk-debug.apk resources.arsc # 把新的resources.arsc放进根下
再使用jarsigner去重签名此包。
使用AS去打开apk看,输出是否同此aapt d 命令的结果一样。
$ aapt l -v debug.apk # 查看APK的文件列表
---------------------------------
Archive: app_signatures.apk
Length Method Size Ratio Offset Date Time CRC-32 Name
-------- ------ ------- ----- ------- ---- ---- ------ ----
1980 Deflate 588 70% 0 04-09-13 18:27 3cb9b35b res/layout/activity_main.xml
1476 Deflate 557 62% 666 04-09-13 18:27 7d5aec49 AndroidManifest.xml
1448 Stored 1448 0% 1288 04-09-13 18:27 ff24da53 resources.arsc
2983 Stored 2983 0% 2780 04-09-13 18:27 0bbf44e1 res/drawable-hdpi/icon.png
447168 Deflate 152707 66% 5819 04-09-13 18:27 69995038 classes.dex
415 Deflate 275 34% 158583 04-09-13 18:27 4dcb1579 META-INF/MANIFEST.MF
468 Deflate 306 35% 158924 04-09-13 18:27 ab016f8e META-INF/CERT.SF
748 Deflate 591 21% 159292 04-09-13 18:27 6aa1bcdb META-INF/CERT.RSA
-------- ------- --- -------
456686 159455 65% 8 files
---------------------------------
$ unzip -l debug.apk
---------------------------------
Archive: app_signatures.apk
Length Date Time Name
--------- ---------- ----- ----
1980 04-09-2013 18:27 res/layout/activity_main.xml
1476 04-09-2013 18:27 AndroidManifest.xml
1448 04-09-2013 18:27 resources.arsc
2983 04-09-2013 18:27 res/drawable-hdpi/icon.png
447168 04-09-2013 18:27 classes.dex
415 04-09-2013 18:27 META-INF/MANIFEST.MF
468 04-09-2013 18:27 META-INF/CERT.SF
748 04-09-2013 18:27 META-INF/CERT.RSA
--------- -------
456686 8 files
Usage用法
~ $ aapt
Android Asset Packaging Tool
Usage:
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
List contents of Zip-compatible archive.
< 列出Zip兼容压缩包的内容 >
aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]
< $ aapt d [接以下元数据-必选] dest.apk >
strings Print the contents of the resource table string pool in the APK.
< 打印apk包的资源表String池的内容 { $ aapt d strings dest.apk} >
badging Print the label and icon for the app declared in APK.
< 打印apk包中的应用声明的标签和图标。 >
permissions Print the permissions from the APK.
< 打印APK中的权限。 >
resources Print the resource table from the APK.
< 打印APK中的资源表。 >
configurations Print the configurations in the APK.
< 打印APK中的配置。 >
xmltree Print the compiled xmls in the given assets.
< 打印指定资源的编译xmls。eg. aapt d xmltree dest.apk res/layout/activity_main.xml >
xmlstrings Print the strings of the given compiled xml assets.
< 打印指定xml资源的字符串strings。同上,看此xml内的使用了的字符串。 >
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,...] \
[-c CONFIGS] [--preferred-density DENSITY] \
[--split CONFIGS [--split CONFIGS]] \
[--feature-of package [--feature-after package]] \
[raw-files-dir [raw-files-dir] ...] \
[--output-text-symbols DIR]
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 which files are output.
< 打包Android资源。它将读取 -M -A -S或raw-files-dir参数所提供的assets资产和resources资源。输出-J -P -F 和-R选项控制的文件。 >
aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
Delete specified files from Zip-compatible archive.
< 删除Zip兼容压缩包指定文件。 >
aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
Add specified files to Zip-compatible archive.
< 添加指定文件到Zip兼容压缩包 >
aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
Do PNG preprocessing on one or several resource folders
and store the results in the output folder.
< 在一个或多个资源文件夹上执行PNG预处理,并将结果存储到输出文件夹中。 >
aapt s[ingleCrunch] [-v] -i input-file -o outputfile
Do PNG preprocessing on a single file.
< 对一个文件进行PNG >
aapt v[ersion]
Print program version.
< 打印程序版本。 >
Modifiers:修改工具项
-a print Android-specific data (resources, manifest) when listing
< 列表时,打印Android特定数据(resources资源, manifest清单)。 >
-c specify which configurations to include.
< 指定要包含的配置。 >
The default is all configurations. The value of the parameter should be a comma separated list of configuration values.
< 默认是所有配置。配置值列表的参数值应该以逗号分隔。>
Locales should be specified as either a language or language-region pair.
< 应将语言环境指定为语言或语言区域对。>
Some examples:
en
port,en
port,land,en_US
-d one or more device assets to include, separated by commas
< 包含一个或多个设备的assets资产,以逗号分隔。 >
-f force overwrite of existing files
< 强制重写已有文件。 >
-g specify a pixel tolerance to force images to grayscale, default 0
< 指定像素公差以强制图片灰度,默认为0. >
-j specify a jar or zip file containing classes to include
< 指定包含类的jar或zip文件。 >
-k junk path of file(s) added
< 添加文件的垃圾目录。 >
-m make package directories under location specified by -J
< 使由-J指定的位置为包目录。 >
-u update existing packages (add new, replace older, remove deleted files)
< 更新存在的包(加新,替旧,删除已删文件)。 >
-v verbose output
< 冗余输出。 >
-x create extending (non-application) resource IDs
< 添加扩展(非应用程序 )资源ID。 >
-z require localization of resource attributes marked with localization="suggested"
< 需要本地化的资源属性用 localization="suggested"标记 >
-A additional directory in which to find raw asset files
< 查找raw asset文件的附加目录 >
-G A file to output proguard options into.
< Proguard选项的输出文件。 >
-F specify the apk file to output
< 指定生成apk文件。 >
-I add an existing package to base include set
< 添加存在包到基包含集。 >
-J specify where to output R.java resource constant definitions
< 指定哪里输出常量定义资源R.java。 >
-M specify full path to AndroidManifest.xml to include in zip
< 包含在Zip中指定AndroidManifest.xml完整路径 >
-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 in the .apk. An empty string means to not compress any files at all.
< 指定附加扩展那些文件会不被压缩存储到.apk中。空串的意思是完全不压缩任何文件。 >
--debug-mode
inserts android:debuggable="true" in to the application node of the manifest, making the application debuggable even on production devices.
< 在manifest的application节点中插入android:debuggable="true",使应用即使在生产设备也能调试。 >
--include-meta-data
when used with "dump badging" also includes meta-data tags.
< 当与"dump badging"一起使用时,也要包括元数据标签。 >
--pseudo-localize
generate resources for pseudo-locales (en-XA and ar-XB).
< 为pseude-locales伪语言环境生成资源(en-XA和ar-XB)。 >
--min-sdk-version
inserts android:minSdkVersion in to manifest. If the version is 7 or higher, the default encoding for resources will be in UTF-8.
< manifest中加入android:minSdkVersion.当版本为7或更高时,资源默认编码使用UTF-8。 >
--target-sdk-version
inserts android:targetSdkVersion in to manifest.
< manifest中加入android:targetSdkVersion。 >
--max-res-version
ignores versioned resource directories above the given value.
< 忽略给定版本号之上的资源目录。 >
--values
when used with "dump resources" also includes resource values.
< 当与"dump resources"一起使用,且包括资源值。 >
--version-code
inserts android:versionCode in to manifest.
< manifest中加入android:versionCode。 >
--version-name
inserts android:versionName in to manifest.
< manifest中加入android:versionName。 >
--replace-version
If --version-code and/or --version-name are specified, these values will replace any value already in the manifest. By default, nothing is changed if the manifest already defines these attributes.
< 当--version-code且或--version-name被指定了,这些值将替换Manifest中已有的任何值。默认情况下,如果manifest中已定义这些属性,则没有任何改变。 >
--custom-package
generates R.java into a different package.
< 将R.java生成不同的包。 >
--extra-packages
generate R.java for libraries. Separate libraries with ':'.
< 为库生成R.java。分开库用':'。 >
--generate-dependencies
generate dependency files in the same directories for R.java and resource package
< 在R.java和资源包的相同目录中生成依赖文件。 >
--auto-add-overlay
Automatically add resources that are only in overlays.
< 自动添加仅覆盖的资源。 >
--preferred-density
Specifies a preference for a particular density. Resources that do not match this density and have variants that are a closer match are removed.
< 指定特定的density密度偏好。不符合此密度且接近匹配的变体的资源将删除。 >
--split
Builds a separate split APK for the configurations listed. This can be loaded alongside the base APK at runtime.
< 为所列配置构建单独的分开apk。这能在运行时与基础apk一起加载。 >
--feature-of
Builds a split APK that is a feature of the apk specified here. Resources in the base APK can be referenced from the the feature APK.
< 构建分开的apk,这是这里指定的apk功能。这个apk功能能引用基础apk的资源。 >
--feature-after
An app can have multiple Feature Split APKs which must be totally ordered.
If --feature-of is specified, this flag specifies which Feature Split APK comes before this one. The first Feature Split APK should not define anything here.
< 一个应用可以有多功特性分开apk,必须完全排序。如果--feature-of被指定,此标志指定哪个特性拆分apk在此之前。第一个功能拆分apk不应该在此定义任何东西。 >
--rename-manifest-package
Rewrite the manifest so that its package name is the package name given here. Relative class names (for example .Foo) will be changed to absolute names with the old package so that the code does not need to change.
< 重写manifest,使此包名为此处给出的包名。相对类名(例如.Foo)将会变更为具有旧包的绝对名称,以便代码不需要更改。 >
--rename-instrumentation-target-package
Rewrite the manifest so that all of its instrumentation components target the given package. Useful when used in conjunction with --rename-manifest-package to fix tests against a package that has been renamed.
< 重写manifest以便其所有的检测组件都针对给定的包。与--rename-manifest-package组合使用以对已重命名的程序包修复测试时有用。 >
--product
Specifies which variant to choose for strings that have product variants
< 指定有产品变体的字符串选择哪个变体。 >
--utf16
changes default encoding for resources to UTF-16. Only useful when API level is set to 7 or higher where the default encoding is UTF-8.
< 改变默认资源编码格式为UTF-16。仅当API级别为7或以上时在默认编码是UTF-8时有效。 >
--non-constant-id
Make the resources ID non constant. This is required to make an R java class that does not contain the final value but is used to make reusable compiled libraries that need to access resources.
< 使资源ID不是常量。这需要创建不含final值的R类,但用于制作可重用的编译库,需要访问资源。 >
--shared-lib
Make a shared library resource package that can be loaded by an application at runtime to access the libraries resources. Implies --non-constant-id.
< 创建可以在运行时由应用程序加载以访问库资源的共享库资源包。暗示: --non-constant-id。 >
--error-on-failed-insert
Forces aapt to return an error if it fails to insert values into the manifest with --debug-mode, --min-sdk-version, --target-sdk-version --version-code and --version-name.
Insertion typically fails if the manifest already defines the attribute.
< 如果不能在manifest中插入--debug-mode,--min-sdk-version,--target-sdk-version,--version-code和--version-name值,强制aapt返回错误。如果manifest已定义了属性,插入通常则会失败。 >
--error-on-missing-config-entry
Forces aapt to return an error if it fails to find an entry for a configuration.
< 如果不能查找配置项,则强制appt返回错误。 >
--output-text-symbols
Generates a text file containing the resource symbols of the R class in the specified folder.
< 生成包含指定文件夹中R类的资源符号的文本文件。 >
--ignore-assets
Assets to be ignored. Default pattern is:
!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~
< 资产被忽略掉。默认模式是:... >
--skip-symbols-without-default-localization
Prevents symbols from being generated for strings that do not have a default localization
< 防止为没有默认本地化的字符串生成符号。 >
--no-version-vectors
Do not automatically generate versioned copies of vector XML resources.
< 不要自动生成版本副本矢量xml资源。 >
Last updated
Was this helpful?