Getting Started
This guide will help you get started with Node-APK to parse Android application packages.
Prerequisites
- Node.js 20 or later
- npm, yarn, or pnpm
Installation
bash
npm install node-apkbash
yarn add node-apkbash
pnpm add node-apkBasic Usage
Import the Library
typescript
import { Apk } from "node-apk";Create an Apk Instance
You can create an Apk instance from either a file path or a Buffer:
typescript
// From file path
const apk = new Apk("/path/to/your/app.apk");
// From Buffer (useful for uploads or in-memory processing)
const buffer = await fs.readFile("/path/to/your/app.apk");
const apk = new Apk(buffer);Extract Manifest Information
typescript
const manifest = await apk.getManifestInfo();
console.log("Package:", manifest.package);
console.log("Version Code:", manifest.versionCode);
console.log("Version Name:", manifest.versionName);
// List all permissions
for (const permission of manifest.permissions) {
console.log("Permission:", permission);
}
// List broadcast receivers
for (const receiver of manifest.receivers) {
console.log("Receiver:", receiver.name);
console.log(" Permission:", receiver.permission);
console.log(" Exported:", receiver.exported);
}Get Localized App Name
typescript
// Get the default app name
const label = await apk.getLabel();
console.log("App Name:", label);
// Get a localized name
const frenchLabel = await apk.getLabel({ locale: "fr" });
console.log("French Name:", frenchLabel);Extract Launcher Icon
typescript
// Get the best available launcher icon
const icon = await apk.getLauncherIcon();
// Get a specific density icon
const hdpiIcon = await apk.getLauncherIcon({ density: "hdpi" });
// Save the icon to a file
await fs.writeFile("icon.png", icon);Get Signing Certificates
typescript
const certs = await apk.getCertificateInfo();
for (const cert of certs) {
console.log("Subject:", cert.subject.get("CN"));
console.log("Issuer:", cert.issuer.get("CN"));
console.log("Valid Until:", cert.validUntil);
// Access the full certificate chain
for (const chainCert of cert.chain) {
console.log(" Chain:", chainCert.subject.get("CN"));
}
}Extract Files from APK
typescript
// Extract a specific file
const manifestXml = await apk.extract("AndroidManifest.xml");
// Extract assets
const configFile = await apk.extract("assets/config.json");
const config = JSON.parse(configFile.toString("utf8"));Error Handling
All methods return Promises and can throw errors:
typescript
import { Apk } from "node-apk";
try {
const apk = new Apk("app.apk");
const manifest = await apk.getManifestInfo();
console.log("Package:", manifest.package);
} catch (error) {
if (error instanceof Error) {
console.error("Failed to parse APK:", error.message);
}
}Next Steps
- Installation - Detailed installation instructions
- API Reference - Complete API documentation
- Examples - More usage examples
- TypeScript - TypeScript-specific guides