← Android binary XML
AXML·Guide
All tools

The AXML tool

Android compiles the XML of an app — AndroidManifest.xml, res/xml/*.xml, layouts, drawables — into binary XML (AXML) when it builds an APK. Android App Bundles (.aab) keep the same files in aapt2's protobuf format instead. The tool reads both and shows the XML again, with the manifest's package, SDK versions, permissions and components, and the settings worth a security review (debuggable, cleartext traffic, backups, exported components, dangerous permissions).

  1. Binary XML
  2. Protobuf XML (App Bundles)
  3. The AXML library

1Binary XML

The file is a series of chunks, each starting with a type (u16), a header size (u16) and a total size (u32), little-endian. The first chunk (type 0x0003) covers the whole file; inside it come:

ChunkTypeContent
string pool0x0001Every name and value of the document, once, in UTF-16 or (modified) UTF-8. Elements and attributes refer to strings by index.
resource map0x0180The resource ids of the first strings: an attribute whose name string is n is the framework attribute with id map[n] (0x01010003 is android:name). Android matches attributes by id, so the name string can be empty or misleading.
start / end namespace0x0100 / 0x0101A prefix and URI coming into or going out of scope.
start element0x0102Line number, comment, namespace, name and the attributes: namespace, name, raw string and a typed value (Res_value: type and 32-bit data — a reference @0x7f…, an integer, a boolean, a colour, a dimension…).
end element0x0103Closes the element.
text0x0104Character data inside an element.

References show as resource ids (@0x7f0a0000); the ARSC tool names them from resources.arsc. Damaged files are read as far as possible and the problems are listed under the overview.

2Protobuf XML (App Bundles)

In an .aab (and in aapt2 link --proto-format output), base/manifest/AndroidManifest.xml and the XML resources are aapt.pb.XmlNode messages from aapt2's Resources.proto: an element with its namespace declarations, attributes (source text, resource id and the compiled Item) and children. References keep their names (@string/app_name). There is no string pool: the tool lists the distinct names and values instead.

3The AXML library

The decoding is lib/axml.js, a JavaScript module with no user interface. It exports the class AndroidXml, a set of static methods; documents and elements are plain objects. Protobuf XML is read with lib/protobuf.js, which the module imports itself. The APK and IPA tools use it, through lib/app-frameworks.js, to read Cordova's config.xml and the manifest's <meta-data>.

import { AndroidXml } from "../lib/axml.js";
MethodWhat it does
AndroidXml.parse(input)An ArrayBuffer or Uint8Array → a document: protobuf XML when the bytes look like it, binary XML otherwise. Throws when the file is neither.
AndroidXml.parseBinary(input), AndroidXml.parseProto(input)One format only.
document{ root, strings, stringCount, utf8, flags, resourceMap, errors, proto }. errors lists what could not be read, as sentences.
element{ type: "element", name, prefix, namespaceUri, attributes, children, line, comment }, plus namespaceDeclarations: [{ prefix, uri }] on the element that declares them. A child is an element or { type: "text", text }.
attribute{ prefix, namespaceUri, name, value: { text, kind }, valueType, valueData, resourceId }; kind is "string", "ref", "num", "bool", "color" or "null".
AndroidXml.isBinary(bytes), AndroidXml.isProto(bytes)Whether the bytes look like binary XML (chunk type 3) or an aapt2 XmlNode.
AndroidXml.toXml(root)The element and its children as indented XML text, without the <?xml?> declaration.
AndroidXml.attribute(element, name, prefix)The attribute with that name (and prefix, when given; null means no namespace), or null.
AndroidXml.attributeText(element, name)The text of android:name, or of name without a namespace, or null.
AndroidXml.walk(element, visit)Calls visit for the element and every element below it.
AndroidXml.manifestSummary(root)What a manifest declares: { package, versionCode, versionName, minSdk, targetSdk, compileSdk, permissions, dangerousPermissions, components: [{ type, name, exported, permission, hasIntentFilter }] }.
AndroidXml.isDangerousPermission(name)True for runtime permissions the user must grant (camera, location, contacts, SMS…).
AndroidXml.formatValue(type, data, raw, strings)A Res_value as text: { text, kind }. strings(index) resolves string values.
AndroidXml.ATTRIBUTE_NAMES, AndroidXml.ANDROID_NAMESPACENames of common framework attribute ids; the android namespace URI.
import { AndroidXml } from "../lib/axml.js";

const manifest = AndroidXml.parse(bytes);
console.log(AndroidXml.toXml(manifest.root));
const summary = AndroidXml.manifestSummary(manifest.root);
console.log(summary.package, summary.targetSdk, summary.dangerousPermissions);
AndroidXml.walk(manifest.root, (element) => {
	if (element.name === "meta-data") {
		console.log(AndroidXml.attributeText(element, "name"), AndroidXml.attributeText(element, "value"));
	}
});