Skip to content

Windows 上的安卓应用运行器:双击 APK 即装,应用以独立窗口与桌面图标运行,自持 QEMU 运行时

perf(size): 镜像改用 xz/LZMA2 极限压缩 + 精简无用资源,安装包 1.81GB→1.32GB

RoutineMiku9103ce0e7fd9
diff --git a/README.md b/README.md
index eb7c9e9..06aa470 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@
到 [Releases](https://github.com/RoutineMiku/apkstart/releases) 下载安装包:
-- **`ApkStart-v*-Setup.exe`**(约 1.0~1.1 GB):**一个 EXE 包含全部运行时**(adb / Android Emulator / 系统镜像),装完首次启动自动把镜像展开到用户目录,**之后不再联网下载任何东西**。装到当前用户目录、不要求管理员权限。
+- **`ApkStart-v*-Setup.exe`**(约 1.3 GB):**一个 EXE 包含全部运行时**(adb / Android Emulator / 系统镜像),装完首次启动自动把镜像展开到用户目录,**之后不再联网下载任何东西**。装到当前用户目录、不要求管理员权限。
- 另有轻量版 `ApkStart-v*-win64-portable.zip`(约 100 MB):首次启动才在后台下载运行时。
**开箱即有的默认行为**(不用去设置里找):
@@ -70,8 +70,8 @@ npm run pack
如果希望「一个 EXE 发出去,对方双击就能跑,不用等下载」,用这条:
```powershell
-# 先把 engine/ 整理成可分发运行时(system.img 压成 .gz,3.1GB → 约 580MB;
-# 同时裁掉 emulator 里用不到的部分:arm64 的 QEMU、Vulkan 后端、多语言包,约 -190MB)
+# 先把 engine/ 整理成可分发运行时(system.img 用 xz/LZMA2 极限压缩,3.1GB → 约 1.1GB;
+# 同时裁掉 emulator 里用不到的部分:arm64 的 QEMU、Vulkan 后端、多语言包、qsn/自检工具、VR 资源)
npm run runtime
# 再打成安装版 EXE(electron-builder nsis 目标,装到当前用户目录)
@@ -79,11 +79,12 @@ npm run build:exe
# 产出 dist/release/ApkStart-<版本>-Setup.exe
```
-体积构成(实测):Electron 约 180MB、emulator 瘦身后约 340MB、系统镜像压缩后约 580MB,
-最终安装包约 1.0~1.1GB。能再压的硬下限就在 system.img 那条(它就是安卓系统本身,无法再裁)。
+体积构成(实测):Electron 约 180MB、emulator 瘦身后约 480MB、系统镜像 xz 压缩后约 1.1GB,
+最终安装包约 1.32GB(相比 gzip 方案省约 490MB)。能再压的硬下限就在 system.img 那条
+(它就是安卓系统本身,且是 verity 保护的镜像,无法从外部裁掉 GMS 组件)。
网络默认走主机 NAT,不创建虚拟网卡,所以也不依赖任何额外驱动。
-首次启动会把 `.gz` 镜像展开到 `%APPDATA%\apkstart\system-images`(约 1 分钟,只做一次),
+首次启动会把 xz 镜像展开到 `%APPDATA%\apkstart\system-images`(约 20 秒,只做一次),
之后每次直接复用。AVD 与已装应用固定存放在 `%APPDATA%\apkstart\avd`,
即使便携版每次解压到临时目录也不会丢。
@@ -95,7 +96,7 @@ ApkStart 是一个**自持**的项目,运行时组件全部由自己下载、
|---|---|---|---|
| adb(platform-tools) | dl.google.com 官方源 | ~8 MB | 安装/启动安卓应用 |
| Android Emulator | dl.google.com 官方源(8 线程并行下载) | ~440 MB | 运行时引擎(自带设备模型与 GPU 转译) |
-| Android 14 通用系统镜像(Google Play x86_64) | dl.google.com 官方源 | ~1.5 GB | 唯一的基础层:x86 应用、仅含 ARM 库的应用、GMS 都能跑,镜像即系统,无需安装 |
+| Android 14 通用系统镜像(Google Play x86_64) | dl.google.com 官方源 | 源镜像 ~3.1 GB(xz 后 ~1.1 GB) | 唯一的基础层:x86 应用、仅含 ARM 库的应用、GMS 都能跑,镜像即系统,无需安装 |
| AEHD 驱动(可选) | dl.google.com 官方源 | ~0.2 MB | 硬件加速(或用 Windows「虚拟机平台」WHPX) |
首次使用时,「运行时」页会引导完成以上部署(**一键部署**):
diff --git a/build/prepare-runtime.js b/build/prepare-runtime.js
index 6b85553..b675dc5 100644
--- a/build/prepare-runtime.js
+++ b/build/prepare-runtime.js
@@ -31,6 +31,32 @@ async function gzipFile(src, dest) {
);
}
+/** 大镜像用 XZ(LZMA2 9e):比 gzip -6 再省 ~25%(system.img 1.5GB→~1.1GB)。
+ * 优先 python(支持 EXTREME 极限档);没有 python 时回退 napi-rs(preset 9)。 */
+async function xzFile(src, dest) {
+ const { spawn } = require('child_process');
+ const ok = await new Promise((resolve) => {
+ const py = spawn('python', ['-c', [
+ 'import lzma,sys,shutil',
+ 'flt=[{"id":lzma.FILTER_LZMA2,"preset":9|lzma.PRESET_EXTREME,"dict_size":1<<27}]',
+ 'z=lzma.LZMAFile(sys.stdout.buffer,mode="wb",format=lzma.FORMAT_XZ,filters=flt)',
+ 'shutil.copyfileobj(sys.stdin.buffer,z); z.close()',
+ ].join(';')], { stdio: ['pipe', 'pipe', 'inherit'], windowsHide: true });
+ const out = fs.createWriteStream(dest);
+ py.stdout.pipe(out);
+ py.on('exit', (c) => resolve(c === 0));
+ py.on('error', () => resolve(false));
+ });
+ if (ok) return;
+ console.log(' (未找到 python,回退 napi-rs preset 9)');
+ const { createCompressStream } = require('@napi-rs/lzma/xz');
+ await pipeline(
+ fs.createReadStream(src),
+ createCompressStream({ preset: 9 }),
+ fs.createWriteStream(dest),
+ );
+}
+
async function main() {
const force = process.argv.includes('--force');
if (fs.existsSync(MARK) && !force) {
@@ -58,7 +84,7 @@ async function main() {
slim(OUT, { aggressive: !process.argv.includes('--safe-slim') });
}
- // 2. 系统镜像:system.img 压成 .gz,其余原样带
+ // 2. 系统镜像:大镜像压成 .xz(运行时 materializeImages 流式解压),其余原样带
const imgRoot = path.join(SRC, 'system-images');
let compressed = 0;
if (fs.existsSync(imgRoot)) {
@@ -71,12 +97,19 @@ async function main() {
for (const f of fs.readdirSync(from)) {
const src = path.join(from, f);
if (!fs.statSync(src).isFile()) continue;
+ // NOTICE.txt 是 GMS 许可文本(~20MB),运行不需要
+ if (/^NOTICE\.txt$/i.test(f)) continue;
if (/^(system|vendor|cache)\.img$/i.test(f) && sizeOf(src) > 32 * 1024 * 1024) {
- // 大镜像压一份,原图不进包
- const gz = path.join(to, `${f}.gz`);
- console.log(`压缩 ${f}(${(sizeOf(src) / 1073741824).toFixed(2)} GB)…`);
+ // 大镜像压一份,原图不进包;已有 .xz(且大小合理)则跳过重复压缩
+ const xz = path.join(to, `${f}.xz`);
+ if (fs.existsSync(xz) && sizeOf(xz) > 32 * 1024 * 1024) {
+ console.log(`跳过 ${f}(已有 .xz ${(sizeOf(xz) / 1048576).toFixed(0)} MB)`);
+ compressed += 1;
+ continue;
+ }
+ console.log(`压缩 ${f}(${(sizeOf(src) / 1073741824).toFixed(2)} GB)→ XZ 9e(较慢,一次性)…`);
// eslint-disable-next-line no-await-in-loop
- await gzipFile(src, gz);
+ await xzFile(src, xz);
compressed += 1;
} else {
fs.copyFileSync(src, path.join(to, f));
diff --git a/build/slim-runtime.js b/build/slim-runtime.js
index cdb04a1..6cc0855 100644
--- a/build/slim-runtime.js
+++ b/build/slim-runtime.js
@@ -29,6 +29,13 @@ const SAFE = [
['emulator/qemu/windows-x86_64/qemu-system-aarch64.exe', 'arm64 的 QEMU 二进制(只发 x86_64 镜像)'],
['emulator/lib64/vulkan', 'Vulkan 后端(固定 -gpu software,删掉退回 swiftshader)'],
['emulator/lib64/qt/translations', '模拟器界面的多语言包(只剩 38px 标题栏)'],
+ ['emulator/emulator-check.exe', 'CI 自检工具(运行时用不到,-16MB)'],
+ ['emulator/qsn.exe', 'QEMU 快照通知助手(emulator.exe 无任何引用,已 strings 实证,-34MB)'],
+ ['emulator/resources/Toren1BD_Main.png', 'VR 全景环境贴图(红果用不到,-3.7MB)'],
+ ['emulator/resources/Toren1BD_Decor.png', 'VR 全景装饰贴图(-3.5MB)'],
+ ['emulator/resources/Toren1BD.obj', 'VR 全景 3D 模型(-3.5MB)'],
+ ['emulator/resources/macroPreviews', '宏操作预览图(-2.7MB)'],
+ ['emulator/resources/default360.mp4', '360° 全景默认视频(-2.4MB)'],
];
/** 激进档目前为空:WebEngine 是硬依赖、gles_angle 是软渲染依赖,都不敢删 */
diff --git a/electron-builder.yml b/electron-builder.yml
index 85aa6e4..38c9e44 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -14,6 +14,18 @@ files:
- LICENSE
- "!**/*.map"
- "!**/node_modules/**"
+ # 运行时解压 .xz 镜像用(NAPI 预编译,无 ABI 问题)
+ - "node_modules/@napi-rs/lzma/**"
+ - "node_modules/@napi-rs/lzma-win32-x64-msvc/**"
+ - "!node_modules/@napi-rs/lzma/*.md"
+ - "!node_modules/@napi-rs/lzma/*.ts"
+ - "!node_modules/@napi-rs/lzma/browser-entry.*"
+
+# 只保留中英文界面语言(Electron locales 从 41MB 降到 ~3MB)
+electronLanguages:
+ - zh-CN
+ - zh-TW
+ - en-US
# 完整运行时(emulator + platform-tools + 系统镜像),由 build/prepare-runtime.js 生成。
# 打进包里之后首次启动不再需要任何下载。
diff --git a/package-lock.json b/package-lock.json
index 168726d..e330174 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,9 @@
"os": [
"win32"
],
+ "dependencies": {
+ "@napi-rs/lzma": "^1.5.3"
+ },
"devDependencies": {
"electron": "^33.4.11",
"electron-builder": "^26.18.0"
@@ -448,6 +451,37 @@
"node": ">= 10.0.0"
}
},
+ "node_modules/@emnapi/core": {
+ "version": "2.0.0-beta.3",
+ "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.3.tgz",
+ "integrity": "sha512-KA+gOBtbifRATmUa/Gpf5C2B2EJ0r4brHUT3XSgACeHREcuiObXH56xd+B3fFsEFbUT04VBEe6MuZiCtMp0tQg==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/wasi-threads": "2.2.0",
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@emnapi/runtime": {
+ "version": "2.0.0-beta.3",
+ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.3.tgz",
+ "integrity": "sha512-ayb/PyyLzpwRyFVxeC0uoEHu59QlB1iWGcGsOpXQcaB/Dc+uGfBmNmpCHp3HmTT0t8lSsMmg3j7+tdJW/TlHjQ==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@emnapi/wasi-threads": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
+ "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
"node_modules/@isaacs/fs-minipass": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz",
@@ -539,6 +573,333 @@
"node": ">= 10.0.0"
}
},
+ "node_modules/@napi-rs/lzma": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma/-/lzma-1.5.3.tgz",
+ "integrity": "sha512-QSIzELPyd2A7mcaDiJEWjwzApoAOWq9PVl9xYq+CxzIwstufv48s8aBgOUr0sgbjGmb15aYU88YKNaFaCaOuhQ==",
+ "license": "MIT",
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/Brooooooklyn"
+ },
+ "optionalDependencies": {
+ "@napi-rs/lzma-android-arm-eabi": "1.5.3",
+ "@napi-rs/lzma-android-arm64": "1.5.3",
+ "@napi-rs/lzma-darwin-arm64": "1.5.3",
+ "@napi-rs/lzma-darwin-x64": "1.5.3",
+ "@napi-rs/lzma-freebsd-x64": "1.5.3",
+ "@napi-rs/lzma-linux-arm-gnueabihf": "1.5.3",
+ "@napi-rs/lzma-linux-arm64-gnu": "1.5.3",
+ "@napi-rs/lzma-linux-arm64-musl": "1.5.3",
+ "@napi-rs/lzma-linux-ppc64-gnu": "1.5.3",
+ "@napi-rs/lzma-linux-riscv64-gnu": "1.5.3",
+ "@napi-rs/lzma-linux-s390x-gnu": "1.5.3",
+ "@napi-rs/lzma-linux-x64-gnu": "1.5.3",
+ "@napi-rs/lzma-linux-x64-musl": "1.5.3",
+ "@napi-rs/lzma-wasm32-wasi": "1.5.3",
+ "@napi-rs/lzma-win32-arm64-msvc": "1.5.3",
+ "@napi-rs/lzma-win32-ia32-msvc": "1.5.3",
+ "@napi-rs/lzma-win32-x64-msvc": "1.5.3"
+ }
+ },
+ "node_modules/@napi-rs/lzma-android-arm-eabi": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-android-arm-eabi/-/lzma-android-arm-eabi-1.5.3.tgz",
+ "integrity": "sha512-Jo8Ej9sTXZO+vHVllHPYxcHVoW4dQe30eLx7wk3H786vv2zy/qIIi5KoO6WhK/VsSBhAb13xbIa/vc4maUgp8Q==",
+ "cpu": [
+ "arm"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-android-arm64": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-android-arm64/-/lzma-android-arm64-1.5.3.tgz",
+ "integrity": "sha512-BUEMluJxOJ/9WkZH/IFyyi3viNQGEByodAHDbmJ/k7mVhabGIxjYBea3MmnyTZoIoqZs/ftAKH7jhVCIj+k6mw==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-darwin-arm64": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-darwin-arm64/-/lzma-darwin-arm64-1.5.3.tgz",
+ "integrity": "sha512-ea46AUzmoGqWnrDP8JNea14TCiVMmxWtaD/d5YjRgh1KbL3YfZ9O2BZzfF7DAF+yrVuAQqS52rHveysjnzYlJA==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-darwin-x64": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-darwin-x64/-/lzma-darwin-x64-1.5.3.tgz",
+ "integrity": "sha512-/vz8UpAe/9fV7JiTrT+lAV9Xk9bK4F28u8JRDNIYdGaT7lXP0r/e7YjDvBuJZ9bJtStW4nn/08q5Q7yfFmsF1Q==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-freebsd-x64": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-freebsd-x64/-/lzma-freebsd-x64-1.5.3.tgz",
+ "integrity": "sha512-gAxemzm8Zk1OaMXihd0L8zeAb/P+71NqhrYnrPVweW3cTXg7XACC+zXQsvENAvHhkroeHCfaMmFupRwfHi+u7A==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-arm-gnueabihf": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-arm-gnueabihf/-/lzma-linux-arm-gnueabihf-1.5.3.tgz",
+ "integrity": "sha512-T7ZvCSEAKGoYSw7vIwdKgk1ZaYl8V1JLTgWSlGhnYBau23R9qZP79ONiF7FTosXnvR8G9RLe9peVuVGS5GI7ig==",
+ "cpu": [
+ "arm"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-arm64-gnu": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-arm64-gnu/-/lzma-linux-arm64-gnu-1.5.3.tgz",
+ "integrity": "sha512-fEfgGb/y8jo2X57cTtMQ62XSD57rxDbpSbT38TSq0gSMKg6A/zq3oOxZLRfoCuZkL3cDtuZMi4fAuo6xIkP5eQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-arm64-musl": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-arm64-musl/-/lzma-linux-arm64-musl-1.5.3.tgz",
+ "integrity": "sha512-Phe10HwfNrtM7U2XsVLhJGePWOgx0BVW2/EWUBq1hoPkmKuUTjbrFj8y4XSTGS5eHMWABUtehnkbX+MPnN5sKg==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-ppc64-gnu": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-ppc64-gnu/-/lzma-linux-ppc64-gnu-1.5.3.tgz",
+ "integrity": "sha512-rhuUE76jYbXZaR5oXAWqvfXzxoZKaCFM1nTH3yrdmz2Jtog5mnFcmyJ9WjDFmUgzQo062p1WfXWm3FA8SJOwaA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-riscv64-gnu": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-riscv64-gnu/-/lzma-linux-riscv64-gnu-1.5.3.tgz",
+ "integrity": "sha512-ogeKmHMV80J1uGYu5Lg4XVacyQxv9wapsEMEKH6beFtouIpo5wZMod5/zGLNHA+sg0/9HIAQbm/bVFJ5flkiQQ==",
+ "cpu": [
+ "riscv64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-s390x-gnu": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-s390x-gnu/-/lzma-linux-s390x-gnu-1.5.3.tgz",
+ "integrity": "sha512-FvFzkI1zzVUqpX21UQdLZ0efTPxDolaCH1bqIp6k7hMTtx0RNwHJgcrsbGXQisAJ8uLWKRKncwNVL8MzcBVxUg==",
+ "cpu": [
+ "s390x"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-x64-gnu": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-x64-gnu/-/lzma-linux-x64-gnu-1.5.3.tgz",
+ "integrity": "sha512-cqF0sRTngwVgnH0y7OV/5zWKWZomMYY71t3gzjtmJou4oPoWQHjxmO1Jo5E3GqUg2bPk+Fp3DcRw1xLAeKs1cg==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-linux-x64-musl": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-linux-x64-musl/-/lzma-linux-x64-musl-1.5.3.tgz",
+ "integrity": "sha512-ZBMasmon/mQmwIKNCWDJagq/zq45vvDQzhSijJSBSIgyef8IRvoD9O4H2lq62Lrq3toHxhlMD2D85jwUVr4QQw==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-wasm32-wasi": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-wasm32-wasi/-/lzma-wasm32-wasi-1.5.3.tgz",
+ "integrity": "sha512-gJ2YpVByn8xNbSCbOwQhCN9Jc2ZQY0ERx/K3XFDldbyiFXCphbEnciptp3bwqcp+WUJvIvpZxcKP1+6tcUEj1g==",
+ "cpu": [
+ "wasm32"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/core": "2.0.0-beta.3",
+ "@emnapi/runtime": "2.0.0-beta.3",
+ "@napi-rs/wasm-runtime": "~1.2.7"
+ },
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-win32-arm64-msvc": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-win32-arm64-msvc/-/lzma-win32-arm64-msvc-1.5.3.tgz",
+ "integrity": "sha512-oB9iJluslRc3bZ3upZ7ZD2tJfICX3tjTsqS8jUUWK+d7PpJei/oZ3YklBLNyczmLZ+JXHYZlBbotIeVCaoNGPw==",
+ "cpu": [
+ "arm64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-win32-ia32-msvc": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-win32-ia32-msvc/-/lzma-win32-ia32-msvc-1.5.3.tgz",
+ "integrity": "sha512-b5HxoRno1C9kS9I9pH9E7uYO9oMEQZ2RuOzAs8+PafoHzcHA5KMzSibNfA//seedILG1w22IS7YfrW4s0+4FvA==",
+ "cpu": [
+ "ia32"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/lzma-win32-x64-msvc": {
+ "version": "1.5.3",
+ "resolved": "https://registry.npmjs.org/@napi-rs/lzma-win32-x64-msvc/-/lzma-win32-x64-msvc-1.5.3.tgz",
+ "integrity": "sha512-cPH8uIK0aaD9KZ0FTPBBPTIvncNHQ2Si3DNTP2rjPWyDRVV+syT2dWvlmkiklKgnRipXtx4eJ+tYQZhG30/+9w==",
+ "cpu": [
+ "x64"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^22.20 || ^24.12 || >=25"
+ }
+ },
+ "node_modules/@napi-rs/wasm-runtime": {
+ "version": "1.2.7",
+ "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.7.tgz",
+ "integrity": "sha512-zJccwplOAbgfZju95IUHazLnx9RAPtPN2YGJXI6UbrgeaR9QfPjGrQL6ERkSAtnVCA4Q+83ApGyaX5zdpCaKkQ==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@tybys/wasm-util": "^0.10.3"
+ },
+ "engines": {
+ "node": "^20.19.0 || ^22.13.0 || >=23.5.0"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/Brooooooklyn"
+ },
+ "peerDependencies": {
+ "@emnapi/core": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3",
+ "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3"
+ }
+ },
"node_modules/@noble/hashes": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
@@ -633,6 +994,16 @@
"node": ">=10"
}
},
+ "node_modules/@tybys/wasm-util": {
+ "version": "0.10.4",
+ "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",
+ "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
"node_modules/@types/cacheable-request": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz",
@@ -3798,7 +4169,7 @@
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
"integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
- "dev": true,
+ "devOptional": true,
"license": "0BSD"
},
"node_modules/type-fest": {
diff --git a/package.json b/package.json
index b9b93d0..0a7a567 100644
--- a/package.json
+++ b/package.json
@@ -46,5 +46,8 @@
"devDependencies": {
"electron": "^33.4.11",
"electron-builder": "^26.18.0"
+ },
+ "dependencies": {
+ "@napi-rs/lzma": "^1.5.3"
}
}
diff --git a/src/core/emulator.js b/src/core/emulator.js
index 34a257c..7ca6e7a 100644
--- a/src/core/emulator.js
+++ b/src/core/emulator.js
@@ -208,7 +208,9 @@ class EmulatorEngine {
/** emulator 依赖这些环境变量定位 SDK / AVD;中文路径一律转 8.3 短路径 */
env(root, plan = {}) {
const safeRoot = doctor.shortPath(root);
- const avdHome = doctor.shortPath(path.join(root, 'avd'));
+ // AVD 目录必须与 provisioner.paths().avdHome 一致:bundled 只读运行时(EXE 旁
+ // resources/runtime)时 root/avd 不存在也不可写,AVD 要落到用户数据目录。
+ const avdHome = doctor.shortPath(this.provisioner.paths().avdHome);
const adbPort = String(plan.adbPort || process.env.ANDROID_ADB_SERVER_PORT || '5044');
return {
...process.env,
diff --git a/src/core/provision.js b/src/core/provision.js
index cc7e65b..80068b1 100644
--- a/src/core/provision.js
+++ b/src/core/provision.js
@@ -467,17 +467,38 @@ class Provisioner {
const srcRoot = path.join(this.root, 'system-images');
const destRoot = path.join(store.DATA_DIR, 'system-images');
const jobs = [];
+ const copies = []; // 压缩镜像之外的文件(kernel-ranchu / ramdisk / 未压缩 .img 等)必须一并落到展开目录
+ const found = new Map(); // dest -> job(同镜像 .xz/.gz 并存时优先 .xz)
const walk = (dir, rel = '') => {
let entries = [];
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch (_) { return; }
for (const e of entries) {
const p = path.join(dir, e.name);
- if (e.isDirectory()) walk(p, path.join(rel, e.name));
- else if (/\.img\.gz$/i.test(e.name)) jobs.push({ src: p, dest: path.join(destRoot, rel, e.name.replace(/\.gz$/i, '')) });
+ if (e.isDirectory()) { walk(p, path.join(rel, e.name)); continue; }
+ // 支持 .img.xz(LZMA2,体积比 .gz 小 ~25%)和旧的 .img.gz
+ if (/\.img\.(xz|gz)$/i.test(e.name)) {
+ const dest = path.join(destRoot, rel, e.name.replace(/\.img\.(xz|gz)$/i, '.img'));
+ const job = { src: p, dest, xz: /\.xz$/i.test(e.name) };
+ const prev = found.get(dest);
+ if (!prev || (job.xz && !prev.xz)) found.set(dest, job);
+ } else {
+ copies.push({ src: p, dest: path.join(destRoot, rel, e.name) });
+ }
}
};
walk(srcRoot);
- if (!jobs.length) return 0;
+ jobs.push(...found.values());
+ if (!jobs.length && !copies.length) return 0;
+
+ // 先补齐非镜像文件(模拟器靠 kernel-ranchu 等定位/引导,缺了会报"还差系统镜像")
+ for (const c of copies) {
+ try {
+ const have = fileSize(c.dest);
+ if (have > 0 && have === fileSize(c.src)) continue;
+ fs.mkdirSync(path.dirname(c.dest), { recursive: true });
+ fs.copyFileSync(c.src, c.dest);
+ } catch (e) { onLog(`复制镜像组件失败:${e.message}`); }
+ }
let done = 0;
for (const j of jobs) {
@@ -488,12 +509,16 @@ class Provisioner {
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve, reject) => {
const { pipeline } = require('stream');
- pipeline(
- fs.createReadStream(j.src),
- zlib.createGunzip(),
- fs.createWriteStream(j.dest),
- (err) => (err ? reject(err) : resolve()),
- );
+ const parts = [fs.createReadStream(j.src)];
+ if (j.xz) {
+ // LZMA2 流式解压;@napi-rs/lzma 是 NAPI 预编译,无 Electron ABI 问题
+ const { createDecompressStream } = require('@napi-rs/lzma/xz');
+ parts.push(createDecompressStream());
+ } else {
+ parts.push(zlib.createGunzip());
+ }
+ parts.push(fs.createWriteStream(j.dest));
+ pipeline(...parts, (err) => (err ? reject(err) : resolve()));
}).catch((e) => onLog(`展开镜像失败:${e.message}`));
done += 1;
}
diff --git a/test/capture-apkstart.ps1 b/test/capture-apkstart.ps1
new file mode 100644
index 0000000..cec9fa8
--- /dev/null
+++ b/test/capture-apkstart.ps1
@@ -0,0 +1,54 @@
+# Capture the ApkStart main window (with embedded Android view) to PNG. v2
+param([string]$Out = "hongguo-final.png")
+$ErrorActionPreference = 'Stop'
+Add-Type -AssemblyName System.Drawing
+Add-Type -TypeDefinition @'
+using System;
+using System.Text;
+using System.Runtime.InteropServices;
+public class W4 {
+ public delegate bool EnumProc(IntPtr h, IntPtr p);
+ [DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc cb, IntPtr p);
+ [DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr h, out int pid);
+ [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);
+ [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
+ [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
+ [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int c);
+ [DllImport("user32.dll")] public static extern int GetWindowTextLength(IntPtr h);
+ [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr h, StringBuilder s, int n);
+ [StructLayout(LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; }
+}
+'@
+$found = New-Object System.Collections.ArrayList
+$cb = [W4+EnumProc]{ param($h, $p)
+ if (-not [W4]::IsWindowVisible($h)) { return $true }
+ $pp = 0
+ [void][W4]::GetWindowThreadProcessId($h, [ref]$pp)
+ $proc = Get-Process -Id $pp -ErrorAction SilentlyContinue
+ if (-not $proc) { return $true }
+ if ($proc.Name -ne 'ApkStart') { return $true }
+ $len = [W4]::GetWindowTextLength($h)
+ $sb = New-Object System.Text.StringBuilder ($len + 2)
+ [void][W4]::GetWindowText($h, $sb, $len + 2)
+ $r = New-Object W4+RECT
+ [void][W4]::GetWindowRect($h, [ref]$r)
+ $w = $r.R - $r.L; $hh = $r.B - $r.T
+ if ($w -lt 200 -or $hh -lt 200) { return $true }
+ [void]$found.Add([PSCustomObject]@{ Hwnd = $h; Title = $sb.ToString(); W = $w; H = $hh; Rect = $r })
+ return $true
+}
+[void][W4]::EnumWindows($cb, [IntPtr]::Zero)
+if ($found.Count -eq 0) { Write-Output 'ERR=no-ApkStart-window'; exit 1 }
+$win = $found | Sort-Object { $_.W * $_.H } -Descending | Select-Object -First 1
+Write-Output ("FOUND: '{0}' {1}x{2}" -f $win.Title, $win.W, $win.H)
+[void][W4]::ShowWindow($win.Hwnd, 9)
+[void][W4]::SetForegroundWindow($win.Hwnd)
+Start-Sleep -Milliseconds 2000
+$r = New-Object W4+RECT
+[void][W4]::GetWindowRect($win.Hwnd, [ref]$r)
+$w = $r.R - $r.L; $hh = $r.B - $r.T
+$bmp = New-Object System.Drawing.Bitmap $w, $hh
+$g = [System.Drawing.Graphics]::FromImage($bmp)
+$g.CopyFromScreen($r.L, $r.T, 0, 0, (New-Object System.Drawing.Size $w, $hh))
+$bmp.Save((Join-Path (Get-Location) $Out), [System.Drawing.Imaging.ImageFormat]::Png)
+Write-Output ("SHOT {0} {1}x{2}" -f $Out, $w, $hh)