Skip to content

Apk

The main class for parsing Android APK files.

Constructor

typescript
new Apk(input: string | Buffer)

Creates a new Apk instance.

Parameters

ParameterTypeDescription
inputstring | BufferFile path or Buffer containing APK data

Example

typescript
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()

typescript
getManifestInfo(): Promise<Manifest>

Parses and returns the AndroidManifest.xml information.

Returns

Promise<Manifest> - Parsed manifest information.

Example

typescript
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()

typescript
getCertificateInfo(): Promise<Certificate[]>

Extracts and returns the signing certificates from the APK.

Returns

Promise<Certificate[]> - Array of signing certificates with full chain support.

Example

typescript
const certs = await apk.getCertificateInfo();

for (const cert of certs) {
  console.log(`Subject: ${cert.subject.get("CN")}`);
  console.log(`Valid until: ${cert.validUntil}`);
}

getResources()

typescript
getResources(): Promise<Resources>

Parses and returns the resource table (resources.arsc).

Returns

Promise<Resources> - Resource table parser instance.

Example

typescript
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()

typescript
getLabel(options?: LabelOptions): Promise<string | undefined>

Resolves and returns the application label with optional locale support.

Parameters

ParameterTypeDescription
optionsLabelOptionsOptional configuration

LabelOptions

typescript
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

typescript
// 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()

typescript
getLauncherIcon(options?: IconOptions): Promise<Buffer>

Extracts and returns the launcher icon with optional density preference.

Parameters

ParameterTypeDescription
optionsIconOptionsOptional configuration

IconOptions

typescript
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

typescript
// 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()

typescript
extract(key: string): Promise<Buffer>

Extracts a file from the APK by its path.

Parameters

ParameterTypeDescription
keystringPath to the file in APK

Returns

Promise<Buffer> - The file contents.

Throws

  • Error - If the file is not found in the APK.

Example

typescript
// 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:

typescript
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);
    }
  }
}

LabelOptions

typescript
interface LabelOptions {
  /** Preferred locale for the label */
  locale?: string;
}

IconOptions

typescript
interface IconOptions {
  /** Preferred icon density */
  density?: IconDensity;
}

IconDensity

typescript
type IconDensity = 
  | "mdpi"    // ~160 dpi
  | "hdpi"    // ~240 dpi
  | "xhdpi"   // ~320 dpi
  | "xxhdpi"  // ~480 dpi
  | "xxxhdpi" // ~640 dpi
  | "nodpi"   // No scaling
  | "anydpi"; // Vector/adaptive

See Also

Released under the MIT License.