@devicefarmer/adbkit-apkreader

中文文档
4.0.0发布于 2026/10/25Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 28.1万

Extracts information from APK files.

原始使用文档
文档目录9 节
  1. Requirements
  2. Getting started
  3. Examples
  4. API
  5. ApkReader
  6. More information
  7. Releasing
  8. Contributing
  9. License

adbkit-apkreader

adbkit-apkreader provides a Node.js API for extracting information from Android APK files. For example, it allows you to read the AndroidManifest.xml of an existing APK file.

Requirements

  • Node.js 22 or newer. Older versions are not supported.

Getting started

Install via NPM:

npm install --save @devicefarmer/adbkit-apkreader

Examples

Read the AndroidManifest.xml of an APK

const util = require('util')
const ApkReader = require('@devicefarmer/adbkit-apkreader')

ApkReader.open('HelloApp.apk')
  .then(reader => reader.readManifest())
  .then(manifest => console.log(util.inspect(manifest, { depth: null })))

TypeScript

The package ships its own type declarations. The shapes of the parsed results are exported on the ApkReader namespace:

import ApkReader from '@devicefarmer/adbkit-apkreader'

const reader = await ApkReader.open('HelloApp.apk')
const manifest: ApkReader.Manifest = await reader.readManifest()
// application has no lists when the manifest has no <application> element.
console.log(manifest.package, manifest.application.launcherActivities ?? [])

With esModuleInterop off, use import ApkReader = require('@devicefarmer/adbkit-apkreader') instead. Other exported types include ApkReader.XmlElement, ApkReader.TypedValue and ApkReader.Attributes.

API

Every method that returns a Promise returns a native one. Versions 3.x and earlier returned Bluebird promises; if you relied on Bluebird-only methods such as .timeout(), .tap() or .return(), wrap the result with Bluebird.resolve() or use the native equivalents.

ApkReader

ApkReader.MANIFEST

A convenience constant with the value 'AndroidManifest.xml'. Can use useful with other API methods in certain circumstances.

ApkReader.open(file)

Alternate syntax to manually creating an ApkReader instance. Files and Buffers are supported, but support for streams might be added at some point.

Note that currently this method cannot reject as the file is opened lazily, but this may change in the future and therefore returns a Promise for fewer future compatibility issues. On a related node, calling the constructor directly is still possible, but discouraged.

  • file The path to the APK file, or a Buffer with its contents.
  • Returns: A Promise that resolves with an ApkReader instance.

reader.readContent(path)

Reads the content of the given file inside the APK.

  • path The path to the file. For example, giving 'META-INF/MANIFEST.MF' as the path would read the content of that file.
  • Returns: A Promise that resolves with a Buffer containing the full contents of the file.

reader.readManifest([options])

Reads and parses the AndroidManifest.xml file inside the APK and returns a simplified object representation of it.

  • options Optional. An Object with the following properties:
    • debug If true, logs every read of the binary XML parser to the console. Defaults to false.
  • Returns: A Promise that resolves with a JavaScript Object representation of the manifest. See example output below. Rejects on error (e.g. if parsing was unsuccessful).
{ versionCode: 1,
  versionName: '1.0',
  package: 'com.example.hello.helloapp.app',
  usesPermissions: [],
  permissions: [],
  permissionTrees: [],
  permissionGroups: [],
  instrumentation: null,
  usesSdk: { minSdkVersion: 7, targetSdkVersion: 19 },
  usesConfiguration: null,
  usesFeatures: [],
  supportsScreens: null,
  compatibleScreens: [],
  supportsGlTextures: [],
  application:
   { theme: 'resourceId:0x7f0b0000',
     label: 'resourceId:0x7f0a000e',
     icon: 'resourceId:0x7f020057',
     debuggable: true,
     allowBackup: true,
     activities:
      [ { label: 'resourceId:0x7f0a000e',
          name: 'com.example.hello.helloapp.app.MainActivity',
          intentFilters:
           [ { actions: [ { name: 'android.intent.action.MAIN' } ],
               categories: [ { name: 'android.intent.category.LAUNCHER' } ],
               data: [] } ],
          metaData: [] } ],
     activityAliases: [],
     launcherActivities:
      [ { label: 'resourceId:0x7f0a000e',
          name: 'com.example.hello.helloapp.app.MainActivity',
          intentFilters:
           [ { actions: [ { name: 'android.intent.action.MAIN' } ],
               categories: [ { name: 'android.intent.category.LAUNCHER' } ],
               data: [] } ],
          metaData: [] } ],
     services: [],
     receivers: [],
     providers: [],
     usesLibraries: [] } }

reader.readXml(path[, options])

Reads and parses the binary XML file at the given path inside the APK file. Attempts to be somewhat compatible with the DOM API.

  • path The path to the binary XML file inside the APK. For example, giving 'AndroidManifest.xml' as the path would parse the manifest (but you'll probably want to use reader.readManifest() instead).
  • options Optional. The same options as reader.readManifest().
  • Returns: A Promise that resolves with a JavaScript Object representation of the root node of the XML file. All nodes including the root node have the properties listed below. Rejects on error (e.g. if parsing was unsuccessful).
    • namespaceURI The namespace URI or null if none.
    • nodeType 1 for element nodes, 2 for attribute nodes, and 4 for CData sections.
    • nodeName The node name.
    • For element nodes, the following additional properties are present:
      • attributes An array of attribute nodes.
      • childNodes An array of child nodes.
    • For attribute nodes, the following additional properties are present:
      • name The attribute name.
      • value The attribute value, if possible to represent as a simple value.
      • typedValue May be available when the attribute represents a complex value. See android.util.TypedValue for more information. Has the following properties:
        • value The value, which might null, String, Boolean, Number or even an Object for the most complex types.
        • type A String representation of the type of the value.
        • rawType A raw integer presentation of the type of the value.
    • For CData nodes, the following additional properties are present:
      • data The CData.
      • typedValue May be available if the section represents a more complex type. See above for details.

reader.usingFileStream(path, action)

Opens a readable Stream to the given file inside the APK and runs the given action with it. The APK file is kept open while the action runs, allowing you to process the stream. Once the action finishes, the APK will be automatically closed.

  • path The path to the file. For example, giving 'META-INF/MANIFEST.MF' as the path would open that file.
  • action(stream) A function that processes the stream somehow. MUST return a Promise that resolves when you're done processing the stream. The value that the Promise resolves with will also be the value that usingFileStream() resolves with.
    • stream A readable Stream of the file content. You should either consume or end the stream yourself before resolving the action.
  • Returns: A Promise that resolves with whatever action resolves with.

More information

Releasing

The package is published to npm as @devicefarmer/adbkit-apkreader by two GitHub Actions workflows:

  1. Run Prepare release with the version as input, for example 3.2.5. It bumps package.json, writes the CHANGELOG.md section from GitHub's generated notes, and pushes release/v3.2.5. It writes nothing to master.
  2. Open the pull request it links to in the job summary, label it ignore-for-release, and merge it once the checks pass.
  3. Run Release on master with the same version. It tags v3.2.5, publishes the GitHub release with the notes from CHANGELOG.md, then compiles the TypeScript, tests and publishes the package to npm with trusted publishing (OIDC), so no npm token is stored anywhere.

The bump goes through a pull request because master is protected. Release refuses to run on any branch but master, so an unmerged release/v* branch cannot be published.

Contributing

See CONTRIBUTING.md.

License

See LICENSE.

Copyright © The OpenSTF Project. All Rights Reserved.

版本与发布记录

@devicefarmer/adbkit-apkreader 共发布 6 个版本,首次发布于 2020/05/16;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.0latest2026/10/2518 天前
3.2.42023/03/303 年前
3.2.32021/06/295 年前
3.2.22020/09/236 年前
3.2.12020/08/286 年前
3.2.02020/05/166 年前

关于 @devicefarmer/adbkit-apkreader 的常见问题

@devicefarmer/adbkit-apkreader 是什么?

Extracts information from APK files.

如何安装 @devicefarmer/adbkit-apkreader?

在项目目录运行 npm install @devicefarmer/adbkit-apkreader,或使用 pnpm add / yarn add / bun add。

@devicefarmer/adbkit-apkreader 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devicefarmer/adbkit-apkreader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@devicefarmer/adbkit-apkreader 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@devicefarmer/adbkit-apkreader 可以商用吗?

@devicefarmer/adbkit-apkreader 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@devicefarmer/adbkit-apkreader 的下载量有多少?

根据 npm 官方下载统计,@devicefarmer/adbkit-apkreader 在 2026/10/12 – 2026/11/10 这 30 天内被下载 281,264 次,日均约 9,375 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devicefarmer/adbkit-apkreader 还在维护吗?

最新版本 4.0.0 发布于 2026/10/25(18 天前);至今共发布 6 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。