aapt(1)

โœจ NAME โœจ

okay bestie, this is aapt (Android Asset Packaging Tool) ๐Ÿ’– aka the tool that packages up your Android resources so your app can actually use them ๐ŸŽ€


๐Ÿงš SYNOPSIS ๐Ÿงš

Here's the basic vibe for every command:

aapt command [ options ] files ...

Now let's check out each command, starting with list ๐Ÿ‘€

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

Peek inside a Zip-compatible archive and see what's in there ๐Ÿฆ‹

aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]

dump has a bunch of WHAT options, and each one gives you a different slice of the APK ๐Ÿ’…

  • strings โ€” prints the contents of the resource table string pool inside the APK ๐Ÿงต
  • badging โ€” prints the label and icon for the app declared in the APK ๐Ÿท๏ธ
  • permissions โ€” prints the permissions from the APK ๐Ÿ”
  • resources โ€” prints the resource table from the APK ๐Ÿ“ฆ
  • configurations โ€” prints the configurations in the APK โš™๏ธ
  • xmltree โ€” prints the compiled XMLs in the assets you give it ๐ŸŒณ
  • xmlstrings โ€” prints the strings of the compiled XML assets you give it ๐Ÿ“

Now for package, which is the big main-character command ๐Ÿ‘‘

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-configurations CONFIGS]
               [raw-files-dir [raw-files-dir] ...]
               [--output-text-symbols DIR]

This one packages up the android resources! It reads assets and resources supplied through the -M, -A, -S, or raw-files-dir arguments. The -J, -P, -F, and -R options decide which files get output ๐ŸŽ€

Next up, remove and add, which are basically your closet organizers for archives ๐Ÿ—‘๏ธโž•

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

Deletes the specified files from a Zip-compatible archive ๐Ÿซ 

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

Adds the specified files to a Zip-compatible archive ๐Ÿ’œ

Now for the PNG preprocessing commands, crunch and singleCrunch ๐Ÿ–ผ๏ธ

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

Does PNG preprocessing on one or several resource folders and stores the results in the output folder โœจ

aapt s[ingleCrunch] [-v] -i input-file -o outputfile

Does PNG preprocessing on a single file ๐ŸŒธ

Last but not least, version ๐Ÿงพ

aapt v[ersion]

Prints the program version. Simple, iconic, no notes ๐Ÿ’…


๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so, the Android Asset Packaging Tool (aapt) takes your application resource files, like the AndroidManifest.xml file and the XML files for your Activities, and compiles them. It also produces an R.java so you can reference your resources from your Java code. literally so useful ๐Ÿ˜ญ๐Ÿซถ


๐ŸŽ€ OPTIONS ๐ŸŽ€

Here's a summary of the options, bestie ๐ŸŒˆ

  • -a โ€” prints Android-specific data (resources, manifest) when listing ๐Ÿ“‹
  • -c โ€” picks which configurations to include. The default is all configurations. The value is a comma-separated list of configuration values, and locales can be a language or a language-region pair. Some examples:
en
port,en
port,land,en_US

The special locale zz_ZZ can go on the list too! It does pseudolocalization on the default locale and modifies all the strings so you can spot the ones that missed the internationalization process ๐Ÿ™ˆ For example:

port,land,zz_ZZ
  • -d โ€” one or more device assets to include, separated by commas ๐Ÿ“ฑ
  • -f โ€” force overwrite of existing files ๐Ÿ’ฅ
  • -g โ€” specifies a pixel tolerance to force images to grayscale. Default is 0 ๐Ÿฉถ
  • -j โ€” specifies a jar or zip file containing classes to include ๐Ÿซ™
  • -k โ€” junk the path of any file(s) you add ๐Ÿ—‘๏ธ
  • -m โ€” makes package directories under the location specified by -J ๐Ÿ“
  • -u โ€” updates existing packages (adds new, replaces older, removes deleted files) ๐Ÿ”„
  • -v โ€” verbose output, for when you want ALL the tea โ˜•
  • -x โ€” creates extending (non-application) resource IDs ๐Ÿงฉ
  • -z โ€” requires localization of resource attributes marked with localization="suggested" ๐ŸŒ
  • -A โ€” an additional directory where raw asset files can be found ๐Ÿ—‚๏ธ
  • -G โ€” a file to output proguard options into ๐Ÿงน
  • -F โ€” specifies the apk file to output ๐Ÿ“ฆ
  • -I โ€” adds an existing package to the base include set โž•
  • -J โ€” specifies where to output the R.java resource constant definitions ๐Ÿงฎ
  • -M โ€” specifies the full path to the AndroidManifest.xml to include in the zip ๐Ÿ“œ
  • -P โ€” specifies where to output the public resource definitions ๐ŸŒ
  • -S โ€” a directory where resources can be found. Multiple directories get scanned, and the first match found (left to right) takes precedence ๐Ÿ‘‘
  • -0 โ€” specifies an additional extension for which those files will not be stored compressed in the .apk. An empty string means not to compress any files at all ๐Ÿซง

Now for the long options, the ones with the big energy โœจ

  • --debug-mode โ€” inserts android:debuggable="true" into the application node of the manifest, making the application debuggable even on production devices.
โš ๏ธ bestie, this one is a real caveat! Because it makes the app debuggable even on production devices, use it carefully ๐Ÿ’€
  • --min-sdk-version โ€” inserts android:minSdkVersion into the manifest. If the version is 7 or higher, the default encoding for resources will be UTF-8 ๐Ÿ”ค
  • --target-sdk-version โ€” inserts android:targetSdkVersion into the manifest ๐ŸŽฏ
  • --max-res-version โ€” ignores versioned resource directories above the given value ๐Ÿ™…โ€โ™€๏ธ
  • --values โ€” when used with "dump resources", also includes resource values ๐Ÿ’Ž
  • --version-code โ€” inserts android:versionCode into the manifest ๐Ÿ”ข
  • --version-name โ€” inserts android:versionName into the manifest ๐Ÿท๏ธ
  • --custom-package โ€” generates R.java into a different package ๐ŸŽ
  • --extra-packages โ€” generates R.java for libraries. Separate libraries with ':' ๐Ÿ“š
  • --generate-dependencies โ€” generates dependency files in the same directories for R.java and the resource package ๐Ÿ•ธ๏ธ
  • --auto-add-overlay โ€” automatically adds resources that are only in overlays ๐Ÿช„
  • --preferred-configurations โ€” like the -c option for filtering out unneeded configurations, but it only expresses a preference. If there's no resource available with the preferred configuration, it won't be stripped ๐Ÿ’โ€โ™€๏ธ
  • --rename-manifest-package โ€” rewrites the manifest so its package name is the one given here. Relative class names (for example .Foo) get changed to absolute names with the old package, so the code doesn't have to change ๐Ÿชช
  • --rename-instrumentation-target-package โ€” rewrites the manifest so all of its instrumentation components target the given package. It's super useful alongside --rename-manifest-package to fix tests against a package that got renamed ๐Ÿงช
  • --product โ€” specifies which variant to choose for strings that have product variants ๐Ÿ›๏ธ
  • --utf16 โ€” changes the default encoding for resources to UTF-16. Only useful when the API level is set to 7 or higher, where the default encoding is UTF-8 ๐Ÿซ 
  • --non-constant-id โ€” makes the resource IDs non-constant. This is required to make an R java class that doesn't contain the final value, but is used to make reusable compiled libraries that need to access resources ๐Ÿ”“
  • --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 ๐Ÿšจ
  • --output-text-symbols โ€” generates a text file containing the resource symbols of the R class in the specified folder ๐Ÿ“
  • --ignore-assets โ€” assets to be ignored ๐Ÿ™ˆ

๐Ÿฆ‹ AUTHOR ๐Ÿฆ‹

aapt was written by The Android Open Source Project. the real MVPs ๐Ÿ‘‘๐Ÿซถ


That's the whole tea, bestie! ๐Ÿ’– This page is for aapt(1) and it was last updated October 15, 2014 ๐ŸŒธโœจ