Apk
The main class for parsing Android APK files.
Constructor
new Apk(input: string | Buffer)Creates a new Apk instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
input | string | Buffer | File path or Buffer containing APK data |
Example
import { Apk } from "node-apk";
// From file path
const apk = new Apk("/path/to/app.apk");
// From Buffer
const buffer = await fs.readFile("/path/to/app.apk");
const apk = new Apk(buffer);Methods
getManifestInfo()
getManifestInfo(): Promise<Manifest>Parses and returns the AndroidManifest.xml information.
Returns
Promise<Manifest> - Parsed manifest information.
Example
const manifest = await apk.getManifestInfo();
console.log(`Package: ${manifest.package}`);
console.log(`Version: ${manifest.versionName}`);TIP
The manifest is cached after the first call. Subsequent calls return the cached instance.
getCertificateInfo()
getCertificateInfo(): Promise<Certificate[]>Extracts and returns the signing certificates from the APK.
Returns
Promise<Certificate[]> - Array of signing certificates with full chain support.
Example
const certs = await apk.getCertificateInfo();
for (const cert of certs) {
console.log(`Subject: ${cert.subject.get("CN")}`);
console.log(`Valid until: ${cert.validUntil}`);
}getResources()
getResources(): Promise<Resources>Parses and returns the resource table (resources.arsc).
Returns
Promise<Resources> - Resource table parser instance.
Example
const resources = await apk.getResources();
const resolved = resources.resolve(0x7f040001);
console.log(`Value: ${resolved[0]?.value}`);TIP
The resources are cached after the first call. Subsequent calls return the cached instance.
getLabel()
getLabel(options?: LabelOptions): Promise<string | undefined>Resolves and returns the application label with optional locale support.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | LabelOptions | Optional configuration |
LabelOptions
interface LabelOptions {
/** Preferred locale for the label (e.g., "en", "fr", "zh") */
locale?: string;
}Returns
Promise<string | undefined> - The resolved label string, or undefined if not found.
Example
// Get default label
const label = await apk.getLabel();
console.log(`App Name: ${label}`);
// Get localized label
const frenchLabel = await apk.getLabel({ locale: "fr" });
console.log(`Nom: ${frenchLabel}`);getLauncherIcon()
getLauncherIcon(options?: IconOptions): Promise<Buffer>Extracts and returns the launcher icon with optional density preference.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | IconOptions | Optional configuration |
IconOptions
interface IconOptions {
/** Preferred icon density */
density?: IconDensity;
}
type IconDensity = "mdpi" | "hdpi" | "xhdpi" | "xxhdpi" | "xxxhdpi" | "nodpi" | "anydpi";Returns
Promise<Buffer> - The icon data (PNG or WebP format).
Example
// Get best available icon
const icon = await apk.getLauncherIcon();
await fs.writeFile("icon.png", icon);
// Get specific density
const hdpiIcon = await apk.getLauncherIcon({ density: "hdpi" });TIP
If the preferred density is not available, the method automatically falls back to the best available icon.
extract()
extract(key: string): Promise<Buffer>Extracts a file from the APK by its path.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Path to the file in APK |
Returns
Promise<Buffer> - The file contents.
Throws
Error- If the file is not found in the APK.
Example
// Extract manifest
const manifestXml = await apk.extract("AndroidManifest.xml");
// Extract assets
const config = await apk.extract("assets/config.json");
const data = JSON.parse(config.toString("utf8"));
// Extract native libraries
const lib = await apk.extract("lib/arm64-v8a/libnative.so");Error Handling
All methods return Promises and can throw errors:
try {
const apk = new Apk("app.apk");
const manifest = await apk.getManifestInfo();
} catch (error) {
if (error instanceof Error) {
if (error.message.includes("Entry not found")) {
console.error("File not found in APK");
} else {
console.error("Failed to parse APK:", error.message);
}
}
}Related Types
LabelOptions
interface LabelOptions {
/** Preferred locale for the label */
locale?: string;
}IconOptions
interface IconOptions {
/** Preferred icon density */
density?: IconDensity;
}IconDensity
type IconDensity =
| "mdpi" // ~160 dpi
| "hdpi" // ~240 dpi
| "xhdpi" // ~320 dpi
| "xxhdpi" // ~480 dpi
| "xxxhdpi" // ~640 dpi
| "nodpi" // No scaling
| "anydpi"; // Vector/adaptiveSee Also
- Manifest - Manifest information
- Certificate - Certificate information
- Resources - Resource parsing
- Examples - Usage examples