npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

autojs6-apkbuilder

v1.1.0

Published

AutoJs6 APK Builder CLI - Node.js wrapper

Readme

AutoJs6 APK Builder

Build and Release GitHub release GitHub license

AutoJs6 提取的独立 APK 打包工具,通过命令行或 GitHub Actions 将 AutoJs6 脚本或项目打包成独立的 Android APK。

代码来源

本项目的核心代码完全从官方 AutoJs6 项目提取,主要区别如下:

与官方版本的区别

  1. 移除插件系统

    • 官方版本包含完整的插件系统支持,可从已安装的插件 APK 中提取 native 库和 assets 资源
    • 本版本移除了所有插件相关代码(ensureAndExtractPluginLibrariesIfNeeded、selectPluginServiceOrThrow、extractLibrariesFromPluginApkOrThrow、extractAssetsFromPluginApkOrThrow 等方法)
  2. 移除 Android 运行时依赖

    • 官方版本依赖 Android Context、AssetManager、PackageManager 等 Android 框架 API
    • 本版本改为直接从 AutoJs6 APK 文件中提取所需资源(template.apk、assets、lib)
  3. 修复 Windows 文件系统兼容性问题

    • 官方版本使用 ApkPackager 解压模板到文件系统
    • 官方 AutoJs6 的资源文件名存在大小写冲突(如 A1.png 和 a1.png),在 Linux 下是不同文件,但在 Windows 文件系统中会被识别为同一文件导致覆盖
    • 本版本使用 FastZipBuilder 直接在内存中处理 ZIP 文件,避免解压到文件系统,从而解决了 Windows 下文件名大小写冲突的问题
  4. 添加命令行接口

    • 新增 ApkBuilderCli.kt 作为命令行入口
    • 支持通过命令行参数配置打包过程

工作原理

本工具的核心代码位于 ApkBuilder.kt,其工作流程如下:

1. 准备阶段 (prepare)

  • 创建构建工作空间和临时目录
  • 加载 AutoJs6 APK 作为模板(template.apk)
  • 提取模板中的 META-INF/services 目录(用于 Rhino 引擎)

2. 配置处理 (withConfig)

  • 读取或创建项目配置(project.json)
  • 处理启动页资源
  • 配置 AndroidManifest.xml(应用名称、版本号、包名等)
  • 生成加密密钥:
    • Key = MD5(packageName + versionName + mainScriptFileName)
    • IV = MD5(buildId + name).take(16)
  • 根据配置准备 assets 和 native libraries

3. 构建阶段 (build)

  • 从模板提取 AndroidManifest.xml 和 resources.arsc
  • 使用 ManifestEditor 修改 AndroidManifest.xml
  • 使用 ARSCDecoder 修改 resources.arsc 中的包名
  • 处理应用图标
  • 将修改后的文件写回 ZIP

4. 脚本加密与打包

  • JavaScript 文件使用 AES 加密:
    • 加密算法:AdvancedEncryptionStandard
    • 加密前写入文件头(EncryptedScriptFileHeader)
  • 将项目文件或脚本文件复制到 assets/project/ 目录
  • 写入更新后的 project.json

5. 签名阶段 (sign)

  • 使用 FastZipBuilder 构建未签名的 APK
  • 复制默认 keystore(default_key_store.bks)或使用自定义 keystore
  • 使用 ApkSigner 进行签名,支持 V1/V2/V3/V4 签名方案
  • 输出最终的签名 APK

环境要求

  • Java 17 或更高版本
  • AutoJs6 APK 文件(作为打包模板)

快速开始

1. 下载工具

Releases 页面下载最新的 apkbuilder-cli.jar 文件。

2. 下载 AutoJs6 APK

AutoJs6 Releases 下载最新的 AutoJs6 APK 文件。

3. 打包你的脚本

打包单个脚本文件

java -jar apkbuilder-cli.jar -a autojs6.apk -s main.js -o myapp.apk

打包项目目录

java -jar apkbuilder-cli.jar -a autojs6.apk -s ./my_project -o myapp.apk

Node.js 使用

本项目提供 Node.js 版本的 API 和 CLI,使用 find-java-home 自动查找 Java 环境。

安装

npm install -g autojs6-apkbuilder

CLI 使用

Node.js CLI 与 Java CLI 参数完全一致:

# 打包单个脚本
autojs6-apkbuilder -a autojs6.apk -s main.js -o myapp.apk

# 打包项目目录
autojs6-apkbuilder -a autojs6.apk -s ./my_project -o myapp.apk

# 使用自定义签名
autojs6-apkbuilder -a autojs6.apk -s ./my_project -o myapp.apk \
  -k my-release-key.keystore -kp mypassword -ka myalias -kpa mykeypassword

API 使用

也可以通过编程方式调用:

const { buildApk } = require('autojs6-apkbuilder');

// 基础用法
await buildApk({
  autojs: 'autojs6.apk',
  source: 'main.js',
  output: 'myapp.apk'
});

// 完整选项
await buildApk({
  autojs: 'autojs6.apk',
  source: './my_project',
  output: 'myapp.apk',
  workspace: './build',
  keystore: 'my-release-key.keystore',
  keystorePassword: 'mypassword',
  keyAlias: 'myalias',
  keyPassword: 'mykeypassword',
  javaPath: '/path/to/java' // 可选,自定义 Java 路径
});

TypeScript 示例:

import { buildApk, ApkBuilderOptions } from 'autojs6-apkbuilder';

const options: ApkBuilderOptions = {
  autojs: 'autojs6.apk',
  source: 'main.js',
  output: 'myapp.apk'
};

await buildApk(options);

命令行参数

| 参数 | 简写 | 必需 | 说明 | |------|------|------|------| | --autojs | -a | 是 | AutoJs6 APK 文件路径 | | --source | -s | 是 | 项目目录或 .js 脚本文件路径 | | --output | -o | 否 | 输出 APK 路径(默认: output.apk) | | --workspace | -w | 否 | 构建工作空间目录(默认: ./build_workspace) | | --keystore | -k | 否 | 自定义 Keystore 路径 | | --keystore-password | -kp | 否 | Keystore 密码(默认: AutoJs6) | | --key-alias | -ka | 否 | Keystore 中的 Key Alias(默认: AutoJs6) | | --key-password | -kpa | 否 | Key 密码(默认与 Keystore 密码相同) | | --help | -h | 否 | 显示帮助信息 |

使用示例

基础用法

# 打包单个脚本
java -jar apkbuilder-cli.jar -a autojs6.apk -s main.js -o myapp.apk

# 打包项目目录
java -jar apkbuilder-cli.jar -a autojs6.apk -s ./my_project -o myapp.apk

使用自定义工作空间

java -jar apkbuilder-cli.jar -a autojs6.apk -s ./my_project -o myapp.apk -w ./build

使用自定义签名

java -jar apkbuilder-cli.jar -a autojs6.apk -s ./my_project -o myapp.apk \
  -k my-release-key.keystore -kp mypassword -ka myalias -kpa mykeypassword

Project Config (project.json)

如果你的项目目录中包含 project.json 配置文件,工具会自动读取并应用以下配置:

{
  "name": "我的应用",
  "packageName": "com.example.myapp",
  "versionName": "1.0.0",
  "versionCode": 1,
  "mainScriptFileName": "main.js",
  "iconPath": "./icon.png",
  "permissions": [
    "android.permission.INTERNET",
    "android.permission.WRITE_EXTERNAL_STORAGE"
  ],
  "signatureScheme": "V1 + V2"
}

如果没有 project.json 文件,工具会自动创建默认配置。

GitHub Action 使用

本项目也可以作为 GitHub Action 在你的工作流中使用。详细文档请参考 ACTION_USAGE.md

快速示例

name: Build APK
on:
  push:
    branches: [main]

jobs:
  build-apk:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      
      - name: Download AutoJs6 APK
        run: |
          wget https://github.com/SuperMonster003/AutoJs6/releases/download/v6.7.0/autojs6-v6.7.0-universal-047ae62e.apk -O autojs6.apk
      
      - name: Build APK
        uses: Steven-Qiang/AutoJs6-ApkBuilder@main
        with:
          autojs: autojs6.apk
          source: ./your-project
          output: my-app.apk
      
      - name: Upload APK
        uses: actions/upload-artifact@v7
        with:
          name: my-app
          path: my-app.apk

从源码构建

如果你想自己构建这个工具:

# 克隆仓库
git clone https://github.com/Steven-Qiang/AutoJs6-ApkBuilder.git
cd AutoJs6-ApkBuilder

# 构建
./gradlew build

# 构建好的 JAR 文件位于 build/libs/ 目录
ls -la build/libs/

核心代码结构

  • ApkBuilderCli.kt - 命令行入口,参数解析
  • ApkBuilder.kt - 核心构建逻辑
  • ManifestEditor.java - AndroidManifest.xml 编辑
  • FastZipBuilder.kt - ZIP 文件快速构建
  • ApkSigner.kt - APK 签名
  • TinySign.java - 轻量级签名实现

致谢

许可证

本项目采用 Mozilla Public License Version 2.0 (MPL-2.0),与 AutoJs6 保持一致。详见 LICENSE 文件。

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

贡献

欢迎提交 Issue 和 Pull Request。

相关链接