mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 21:50:44 +00:00
版本号 1.7.1 -> 1.8.0(8 个文件,13 处)。
写了个 bump_180.py 统一处理 —— 版本号散落在
Python / Java manifest / PowerShell / Inno Setup / 测试里,
手动改必漏;而且 .ps1 必须保留 UTF-8 BOM。
==================== 一、隧道稳定性(用户撞上 1033/502/530)====================
1) 4G 链路会**静默断开 TCP 连接**(不发 FIN/RST,双方都以为还活着),
Linux 默认要 2 小时才发现 -> 改成 keepalive 30 秒 + 每 10 秒探测。
实测 60 秒内发现并重连。
2) 隧道连接数 2 -> 4。只剩 1 条连接时跨机房回源会失败
(实测可用率 0/12,提到 4 条后 12/12)。
3) 掉电重启后恢复慢:原来开机 2 分 10 秒公网才可用。
根因是 systemd-networkd-wait-online 等一个不归它管的网络
(wlan0 是 NetworkManager 管的),干等 2 分钟超时失败,
把 network-online.target 一起拖住。
mask 掉它之后:启动 17.3 秒,掉电重启 24 秒公网可用。
4) 看门狗两次翻车都是我造成的,都修了:
a) 我先加了"确认故障立刻重启",但隧道重建 4 条连接要 30~60 秒,
MIN_RESTART_GAP=45 导致**还没建齐就被下一次重启打断**,
死循环,每 50 秒重启一次 -> 加 150 秒宽限期
b) 宽限期又带来"链路持续差时什么都不做"的问题
-> 增加"本次重启后建齐过吗"的判断:
建齐过又垮 = 真故障,立刻重启
从没建齐 = 还在努力,继续等
5) 顺手修:看门狗状态文件里的变量在函数定义前被引用,
set -u 下报 "BUILT: 未绑定的变量"。
==================== 二、中转管理后台重做 ====================
原来的管理页是几百行内联在 relay.py 的 f-string 里,
改一处样式要在一堆转义花括号里翻。拆成独立模块 relay/admin.py。
新设计(对齐官网那套白色简洁):
吸顶顶栏 -> 公网地址(最大权重,这是用户最需要复制的)
-> 四个数字卡 -> 设备表 -> 工具卡(体检 + 下载)
空状态给图标+引导文案;窄屏表格自动变卡片。
relay.py 从 2089 行缩到 1500 行左右。
修了三个我自己引入的 bug:
a) 响应头类型写错,浏览器把整页 HTML 当纯文本显示
(用户看到的是"一屏源码")。教训:200 不等于页面能看,
当时只验了状态码和字节数。
b) 顶栏用了固定 height:62px,装不下"标题+副标题+版本信息"两行,
内容被顶出容器 -> 标题看不见、徽章压在字上。
c) do_HEAD 没处理 /download/ 路径,HEAD 一个 APK 返回
Content-Length: 0 + text/plain,下载器会误判成空文件。
同时发现 _head_info 里对 bytes 调 .encode() —— 加 _as_bytes() 兜住。
==================== 三、其它 ====================
* 设备记录只增不减:实测一天攒 75 条僵尸,/v1/health 从几 KB 涨到 20KB。
加 DEVICE_TTL(6 小时)自动清,占用的配对码一起释放
(管理页曾显示"配对码占用 131"但一台设备都没有)。
* HEAD 请求支持(原来一律 501)。
* 官网新增产品展示:手表界面预览(颜色/布局与真实手表一致)、
电脑端真实截图、两种连接方式对比图。
* 加了一份 docs/免费托管方案.md(含一个纠错:上一版推荐的
ClawCloud Run 已在 2026-05-11 关停)。
==================== 验收 ====================
全量回归 33 个阶段全部通过
安装包完整周期 20/20(静默装入 7 秒、卸载 0.6 秒、无残留)
网页响应头 12/12
公网可用率 26/30 = 86%(底层 4G 丢包 30%,是这个上限)
发布产物 安装包 14.37MB / 服务端 0.20MB / 手表 0.19MB
134 lines
5.2 KiB
PowerShell
134 lines
5.2 KiB
PowerShell
# 用 aapt2 + javac + d8 + zipalign + apksigner 手工构建 APK(不需要 Gradle)
|
||
# 用法: powershell -File android\build_apk.ps1
|
||
#
|
||
# 注意:刻意不用 $ErrorActionPreference="Stop"。
|
||
# 原生工具的告警(javac 的 deprecation note 等)会写 stderr,
|
||
# 在 Stop 模式下会被 PowerShell 当成致命错误中断构建。
|
||
# 改为每一步显式检查 $LASTEXITCODE。
|
||
$ErrorActionPreference = "Continue"
|
||
|
||
$android = $PSScriptRoot # LanRemote/android(本脚本所在目录)
|
||
$root = Split-Path -Parent $android # LanRemote
|
||
$tc = Join-Path $root "..\starklink\toolchain"
|
||
$jdk = Join-Path $tc "jdk17"
|
||
$sdk = Join-Path $tc "android-sdk"
|
||
$bt = Join-Path $sdk "build-tools\34.0.0"
|
||
$androidJar = Join-Path $sdk "platforms\android-34\android.jar"
|
||
$keystore = Join-Path $tc "debug.keystore"
|
||
|
||
$javac = Join-Path $jdk "bin\javac.exe"
|
||
$keytool = Join-Path $jdk "bin\keytool.exe"
|
||
$jar = Join-Path $jdk "bin\jar.exe"
|
||
|
||
$aapt2 = Join-Path $bt "aapt2.exe"
|
||
$zipalign = Join-Path $bt "zipalign.exe"
|
||
$apksigner= Join-Path $bt "apksigner.bat"
|
||
$d8 = Join-Path $bt "d8.bat"
|
||
|
||
$work = Join-Path $android "build"
|
||
$outDir = Join-Path $root "dist"
|
||
$apkName = "ykxmz-watch-1.8.0.apk"
|
||
|
||
function Step($text) { Write-Host "`n=== $text ===" -ForegroundColor Cyan }
|
||
|
||
# 前置检查
|
||
foreach ($tool in @($javac, $aapt2, $d8, $zipalign, $apksigner)) {
|
||
if (-not (Test-Path $tool)) { throw "缺少工具: $tool" }
|
||
}
|
||
if (-not (Test-Path $androidJar)) { throw "缺少 android.jar: $androidJar" }
|
||
if (-not (Test-Path $keystore)) { throw "缺少签名用 keystore: $keystore" }
|
||
|
||
$env:JAVA_HOME = $jdk
|
||
$env:PATH = "$(Join-Path $jdk 'bin');$env:PATH"
|
||
|
||
if (Test-Path $work) { Remove-Item -Recurse -Force $work }
|
||
New-Item -ItemType Directory -Force -Path $work | Out-Null
|
||
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
|
||
|
||
# ---------------- 1. 编译资源 ----------------
|
||
Step "1/6 aapt2 compile 资源"
|
||
$compiled = Join-Path $work "res.zip"
|
||
& $aapt2 compile --dir (Join-Path $android "res") -o $compiled
|
||
if ($LASTEXITCODE -ne 0) { throw "aapt2 compile 失败" }
|
||
|
||
# ---------------- 2. 链接资源 + 生成 R.java ----------------
|
||
Step "2/6 aapt2 link 生成资源表与 R.java"
|
||
$genDir = Join-Path $work "gen"
|
||
New-Item -ItemType Directory -Force -Path $genDir | Out-Null
|
||
$unsigned = Join-Path $work "app-unsigned.apk"
|
||
& $aapt2 link `
|
||
-o $unsigned `
|
||
-I $androidJar `
|
||
--manifest (Join-Path $android "AndroidManifest.xml") `
|
||
-R $compiled `
|
||
--java $genDir `
|
||
--min-sdk-version 24 `
|
||
--target-sdk-version 34 `
|
||
--version-code 5 `
|
||
--version-name "1.8.0" `
|
||
--auto-add-overlay
|
||
if ($LASTEXITCODE -ne 0) { throw "aapt2 link 失败" }
|
||
|
||
# ---------------- 3. 编译 Java ----------------
|
||
Step "3/6 javac 编译 Java 源码"
|
||
$classesDir = Join-Path $work "classes"
|
||
New-Item -ItemType Directory -Force -Path $classesDir | Out-Null
|
||
|
||
$javaSources = @()
|
||
$javaSources += Get-ChildItem -Recurse -Filter *.java -Path (Join-Path $android "src") | ForEach-Object { $_.FullName }
|
||
$javaSources += Get-ChildItem -Recurse -Filter R.java -Path $genDir -ErrorAction SilentlyContinue | ForEach-Object { $_.FullName }
|
||
if ($javaSources.Count -eq 0) { throw "没有找到 Java 源文件" }
|
||
Write-Host "源文件 $($javaSources.Count) 个"
|
||
|
||
& $javac -source 8 -target 8 -nowarn -Xlint:none -encoding UTF-8 `
|
||
-bootclasspath $androidJar `
|
||
-d $classesDir `
|
||
$javaSources 2>&1 | Out-String | Write-Host
|
||
if ($LASTEXITCODE -ne 0) { throw "javac 编译失败" }
|
||
|
||
# ---------------- 4. d8 转 dex ----------------
|
||
Step "4/6 d8 转换为 classes.dex"
|
||
$classesJar = Join-Path $work "classes.jar"
|
||
& $jar cf $classesJar -C $classesDir .
|
||
if ($LASTEXITCODE -ne 0) { throw "打包 classes.jar 失败" }
|
||
|
||
$dexDir = Join-Path $work "dex"
|
||
New-Item -ItemType Directory -Force -Path $dexDir | Out-Null
|
||
& $d8 --lib $androidJar --min-api 24 --output $dexDir $classesJar 2>&1 | Out-String | Write-Host
|
||
if ($LASTEXITCODE -ne 0) { throw "d8 失败" }
|
||
$dex = Join-Path $dexDir "classes.dex"
|
||
if (-not (Test-Path $dex)) { throw "未生成 classes.dex" }
|
||
Write-Host ("classes.dex 大小 {0:N1} KB" -f ((Get-Item $dex).Length / 1KB))
|
||
|
||
# ---------------- 5. 组装 APK ----------------
|
||
Step "5/6 组装 APK"
|
||
& python (Join-Path $root "_build\pack_apk.py") $unsigned $dex
|
||
if ($LASTEXITCODE -ne 0) { throw "写入 classes.dex 失败" }
|
||
|
||
$aligned = Join-Path $work "app-aligned.apk"
|
||
& $zipalign -f 4 $unsigned $aligned
|
||
if ($LASTEXITCODE -ne 0) { throw "zipalign 失败" }
|
||
|
||
# ---------------- 6. 签名 ----------------
|
||
Step "6/6 apksigner 签名"
|
||
$final = Join-Path $outDir $apkName
|
||
if (Test-Path $final) { Remove-Item $final -Force }
|
||
& $apksigner sign `
|
||
--ks $keystore `
|
||
--ks-pass pass:android `
|
||
--key-pass pass:android `
|
||
--ks-key-alias androiddebugkey `
|
||
--v1-signing-enabled true `
|
||
--v2-signing-enabled true `
|
||
--out $final `
|
||
$aligned
|
||
if ($LASTEXITCODE -ne 0) { throw "签名失败" }
|
||
|
||
Step "验证签名"
|
||
& $apksigner verify --print-certs $final
|
||
if ($LASTEXITCODE -ne 0) { throw "签名校验失败" }
|
||
|
||
Step "构建完成"
|
||
Write-Host ("APK: {0}" -f $final) -ForegroundColor Green
|
||
Write-Host ("大小: {0:N2} MB" -f ((Get-Item $final).Length / 1MB)) -ForegroundColor Green
|