查看AAPT命令格式

看到这里,有很多开发者可能会问:笔者是如何记得这么多的指令和它们的参数的?答案就是——其实笔者也不记得。

那么笔者是如何获取这些指令的使用方法的呢?相信经常使用Linux系统的开发者应该很清楚,通常终端程序都会有帮助,AAPT工具同样是这样。在终端下直接执行./aapt指令就可以获取所有的使用方法,显示结果如下所示。

  1. 23.0.2 ./aapt
  2. Android Asset Packaging Tool
  3.  
  4. Usage:
  5. aapt l[ist] [-v] [-a] file.{zip,jar,apk}
  6. List contents of Zip-compatible archive.
  7.  
  8. aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]
  9. strings Print the contents of the resource table string pool in the APK.
  10. badging Print the label and icon for the app declared in APK.
  11. permissions Print the permissions from the APK.
  12. resources Print the resource table from the APK.
  13. configurations Print the configurations in the APK.
  14. xmltree Print the compiled xmls in the given assets.
  15. xmlstrings Print the strings of the given compiled xml assets.
  16.  
  17. aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \
  18. [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \
  19. [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \
  20. [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \
  21. [--rename-manifest-package PACKAGE] \
  22. [--rename-instrumentation-target-package PACKAGE] \
  23. [--utf16] [--auto-add-overlay] \
  24. [--max-res-version VAL] \
  25. [-I base-package [-I base-package ...]] \
  26. [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \
  27. [-S resource-sources [-S resource-sources ...]] \
  28. [-F apk-file] [-J R-file-dir] \
  29. [--product product1,product2,...] \
  30. [-c CONFIGS] [--preferred-density DENSITY] \
  31. [--split CONFIGS [--split CONFIGS]] \
  32. [--feature-of package [--feature-after package]] \
  33. [raw-files-dir [raw-files-dir] ...] \
  34. [--output-text-symbols DIR]
  35.  
  36. Package the android resources. It will read assets and resources that are
  37. supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R
  38. options control which files are output.
  39.  
  40. aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
  41. Delete specified files from Zip-compatible archive.
  42.  
  43. aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
  44. Add specified files to Zip-compatible archive.
  45.  
  46. aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
  47. Do PNG preprocessing on one or several resource folders
  48. and store the results in the output folder.
  49.  
  50. aapt s[ingleCrunch] [-v] -i input-file -o outputfile
  51. Do PNG preprocessing on a single file.
  52.  
  53. aapt v[ersion]
  54. Print program version.
  55.  
  56. Modifiers:
  57. -a print Android-specific data (resources, manifest) when listing
  58. -c specify which configurations to include. The default is all
  59. configurations. The value of the parameter should be a comma
  60. separated list of configuration values. Locales should be specified
  61. as either a language or language-region pair. Some examples:
  62. en
  63. port,en
  64. port,land,en_US
  65. -d one or more device assets to include, separated by commas
  66. -f force overwrite of existing files
  67. -g specify a pixel tolerance to force images to grayscale, default 0
  68. -j specify a jar or zip file containing classes to include
  69. -k junk path of file(s) added
  70. -m make package directories under location specified by -J
  71. -u update existing packages (add new, replace older, remove deleted files)
  72. -v verbose output
  73. -x create extending (non-application) resource IDs
  74. -z require localization of resource attributes marked with
  75. localization="suggested"
  76. -A additional directory in which to find raw asset files
  77. -G A file to output proguard options into.
  78. -F specify the apk file to output
  79. -I add an existing package to base include set
  80. -J specify where to output R.java resource constant definitions
  81. -M specify full path to AndroidManifest.xml to include in zip
  82. -P specify where to output public resource definitions
  83. -S directory in which to find resources. Multiple directories will be scanned
  84. and the first match found (left to right) will take precedence.
  85. -0 specifies an additional extension for which such files will not
  86. be stored compressed in the .apk. An empty string means to not
  87. compress any files at all.
  88. --debug-mode
  89. inserts android:debuggable="true" in to the application node of the
  90. manifest, making the application debuggable even on production devices.
  91. --include-meta-data
  92. when used with "dump badging" also includes meta-data tags.
  93. --pseudo-localize
  94. generate resources for pseudo-locales (en-XA and ar-XB).
  95. --min-sdk-version
  96. inserts android:minSdkVersion in to manifest. If the version is 7 or
  97. higher, the default encoding for resources will be in UTF-8.
  98. --target-sdk-version
  99. inserts android:targetSdkVersion in to manifest.
  100. --max-res-version
  101. ignores versioned resource directories above the given value.
  102. --values
  103. when used with "dump resources" also includes resource values.
  104. --version-code
  105. inserts android:versionCode in to manifest.
  106. --version-name
  107. inserts android:versionName in to manifest.
  108. --replace-version
  109. If --version-code and/or --version-name are specified, these
  110. values will replace any value already in the manifest. By
  111. default, nothing is changed if the manifest already defines
  112. these attributes.
  113. --custom-package
  114. generates R.java into a different package.
  115. --extra-packages
  116. generate R.java for libraries. Separate libraries with ':'.
  117. --generate-dependencies
  118. generate dependency files in the same directories for R.java and resource package
  119. --auto-add-overlay
  120. Automatically add resources that are only in overlays.
  121. --preferred-density
  122. Specifies a preference for a particular density. Resources that do not
  123. match this density and have variants that are a closer match are removed.
  124. --split
  125. Builds a separate split APK for the configurations listed. This can
  126. be loaded alongside the base APK at runtime.
  127. --feature-of
  128. Builds a split APK that is a feature of the apk specified here. Resources
  129. in the base APK can be referenced from the the feature APK.
  130. --feature-after
  131. An app can have multiple Feature Split APKs which must be totally ordered.
  132. If --feature-of is specified, this flag specifies which Feature Split APK
  133. comes before this one. The first Feature Split APK should not define
  134. anything here.
  135. --rename-manifest-package
  136. Rewrite the manifest so that its package name is the package name
  137. given here. Relative class names (for example .Foo) will be
  138. changed to absolute names with the old package so that the code
  139. does not need to change.
  140. --rename-instrumentation-target-package
  141. Rewrite the manifest so that all of its instrumentation
  142. components target the given package. Useful when used in
  143. conjunction with --rename-manifest-package to fix tests against
  144. a package that has been renamed.
  145. --product
  146. Specifies which variant to choose for strings that have
  147. product variants
  148. --utf16
  149. changes default encoding for resources to UTF-16. Only useful when API
  150. level is set to 7 or higher where the default encoding is UTF-8.
  151. --non-constant-id
  152. Make the resources ID non constant. This is required to make an R java class
  153. that does not contain the final value but is used to make reusable compiled
  154. libraries that need to access resources.
  155. --shared-lib
  156. Make a shared library resource package that can be loaded by an application
  157. at runtime to access the libraries resources. Implies --non-constant-id.
  158. --error-on-failed-insert
  159. Forces aapt to return an error if it fails to insert values into the manifest
  160. with --debug-mode, --min-sdk-version, --target-sdk-version --version-code
  161. and --version-name.
  162. Insertion typically fails if the manifest already defines the attribute.
  163. --error-on-missing-config-entry
  164. Forces aapt to return an error if it fails to find an entry for a configuration.
  165. --output-text-symbols
  166. Generates a text file containing the resource symbols of the R class in the
  167. specified folder.
  168. --ignore-assets
  169. Assets to be ignored. Default pattern is:
  170. !.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~
  171. --skip-symbols-without-default-localization
  172. Prevents symbols from being generated for strings that do not have a default
  173. localization
  174. --no-version-vectors
  175. Do not automatically generate versioned copies of vector XML resources.

这份文档解释了AAPT所能够使用的各种指令。如果开发者在使用过程中不记得某些指令的参数或者使用方法,那么直接使用这个指令就可以获取到你想要的内容了。