/** * 列出 AAR 里的类名,并测一下下载源速度。 * 用法: node scripts/probe-misc.mjs */ import { spawnSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; const WORK = 'C:\\Android\\probe'; // 1) xelement 里有哪些类 const xeDir = path.join(WORK, 'x-xelement'); console.log('x-xelement 内容:', fs.existsSync(xeDir) ? fs.readdirSync(xeDir).join(', ') : '(不存在)'); const jar = path.join(xeDir, 'classes.jar'); if (fs.existsSync(jar)) { const res = spawnSync('jar', ['tf', jar], { encoding: 'utf8' }); const all = (res.stdout || '').split('\n').filter(Boolean); console.log('类总数:', all.length); console.log('含 Behaviors/XElement 的类:'); console.log(all.filter((c) => /Behavior|XElement/i.test(c)).slice(0, 20).join('\n')); } // 2) 测速:分别从谷歌和腾讯镜像拉前 8MB async function speed(label, url, bytes = 8 * 1024 * 1024) { const started = Date.now(); try { const res = await fetch(url, { headers: { Range: `bytes=0-${bytes - 1}` }, signal: AbortSignal.timeout(60000), }); if (!res.ok) { console.log(`${label}: HTTP ${res.status}`); return; } const buf = Buffer.from(await res.arrayBuffer()); const secs = (Date.now() - started) / 1000; console.log(`${label}: ${(buf.length / 1024 / 1024).toFixed(1)}MB / ${secs.toFixed(1)}s = ${(buf.length / 1024 / 1024 / secs).toFixed(2)} MB/s`); } catch (err) { console.log(`${label}: ERR ${err.message}`); } } await speed('google ', 'https://dl.google.com/android/repository/commandlinetools-win-11076708_latest.zip'); await speed('tencent ', 'https://mirrors.cloud.tencent.com/AndroidSDK/commandlinetools-win-11076708_latest.zip'); await speed('aliyun ', 'https://mirrors.aliyun.com/android.googlesource.com/commandlinetools-win-11076708_latest.zip');