AAB Parser
raw JSON →aab-parser is a lightweight, asynchronous Android App Bundle (AAB) parser written entirely in TypeScript. It provides functionality to extract key manifest attributes from an AAB file, either as a strongly typed `Manifest` object (a subset of common attributes) or a raw JSON object with more comprehensive data. A key differentiator is its pure Node.js implementation, which means it does not require a Java Development Kit (JDK) installation, unlike many other AAB inspection tools. The current stable version is 1.0.1, released recently after its initial 1.0.0 debut, suggesting an early but active development phase with releases focused on stability and minor enhancements rather than a fixed cadence. It is primarily used for programmatic inspection of AAB metadata in build pipelines or analysis tools.
Common errors
error SyntaxError: await is only valid in async functions and the top level bodies of modules ↓
parseAabManifest or parseAabManifestJSON in an async function, or ensure your project is configured as an ESM module with Node.js version supporting top-level await (Node.js 14.8+). error Error: ENOENT: no such file or directory, open 'path/to/your/bundle.aab' ↓
error TypeError: Cannot read properties of undefined (reading 'packageName') ↓
try...catch) around AAB parsing calls. Log the error to understand the underlying cause. Ensure the AAB file is valid and not corrupt. Warnings
gotcha The `Manifest` type and the `parseAabManifest` function return a strict subset of AAB manifest attributes. If you require full, untyped manifest data, use `parseAabManifestJSON` instead. ↓
gotcha All parsing functions in `aab-parser` are asynchronous and return Promises. Synchronous usage will result in an unhandled promise rejection or a `TypeError` if `await` is not used correctly. ↓
gotcha The README example uses CommonJS `require()`. While this might work, in modern TypeScript and Node.js projects, ESM `import` statements are preferred for better type inference, tree-shaking, and consistency. Mixing module systems can lead to build or runtime issues. ↓
Install
npm install aab-parser yarn add aab-parser pnpm add aab-parser Imports
- parseAabManifest wrong
const aabParser = require('aab-parser'); aabParser.parseAabManifest(...);correctimport { parseAabManifest } from 'aab-parser'; - parseAabManifestJSON wrong
const { parseAabManifestJSON } = require('aab-parser');correctimport { parseAabManifestJSON } from 'aab-parser'; - Manifest wrong
import { Manifest } from 'aab-parser';correctimport type { Manifest } from 'aab-parser';
Quickstart
import { parseAabManifest, Manifest } from 'aab-parser';
import * as path from 'path';
import { promises as fs } from 'fs';
// Ensure you have an 'example.aab' file in your project root or specify a path.
// For testing, you might use a dummy AAB or a real one from a build process.
const AAB_FILE_PATH = process.env.AAB_PATH ?? path.join(__dirname, 'example.aab');
async function main() {
try {
// Create a dummy AAB file for demonstration if it doesn't exist
// In a real scenario, this file would be provided.
try {
await fs.access(AAB_FILE_PATH);
} catch (error) {
console.warn(`AAB file not found at ${AAB_FILE_PATH}. This example requires an AAB file to run fully.`);
console.warn("Creating a placeholder. Please replace with a real AAB for actual parsing.");
await fs.writeFile(AAB_FILE_PATH, Buffer.from('PK\x03\x04... (truncated for brevity, a real AAB is much larger)', 'binary'));
}
console.log(`Parsing AAB manifest from: ${AAB_FILE_PATH}`);
const manifest: Manifest = await parseAabManifest(AAB_FILE_PATH);
console.log('Parsed AAB Manifest:');
console.log(manifest);
// Example of accessing specific fields
console.log(`Package Name: ${manifest.packageName}`);
console.log(`Version Code: ${manifest.versionCode}`);
console.log(`Version Name: ${manifest.versionName}`);
} catch (error) {
console.error('Error parsing AAB manifest:', error);
}
}
main();