diff --git a/AGENTS.md b/AGENTS.md index 4745993..289fd56 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,6 +13,7 @@ | 目录 | 作用 | 主要语言/格式 | | --- | --- | --- | +| `android_agent/` | 手机直接联网的 Android 设备端,Kotlin 传统 View、前台服务与 Rust JNI 网关;不申请运行时权限 | Kotlin、Rust、Gradle Kotlin DSL、XML、TOML | | `agent/` | 无界面多手机守护程序 ads-agent、独立监督进程、私有 IPC 和远程管理;兼容单设备参数;源码在 `src/` | Rust、TOML | | `ctl/` | adsctl 命令行管理端,本机/远程设备、配置、日志、重启及系统启动托管;源码在 `src/` | Rust、TOML | | `usb/` | 可选 ads-usb 本机虚拟 ADB USB 设备,提供回环 USB/IP、描述符和 ADB 帧适配;Windows 使用已签名 USBip 虚拟控制器,Linux 使用内核 vhci_hcd(CLI) | Rust、TOML | @@ -30,7 +31,7 @@ | `desktop/Ads.Desktop.Smoke/` | 桌面离屏布局、连接及可选真机冒烟验证入口 | C#、XML(csproj) | | `deploy/` | 服务器/设备端部署脚本与 Caddy、Nginx、systemd、launchd 配置示例 | Shell、服务/代理配置、XML(plist)、Markdown | | `deploy/windows/` | Windows 设备端准备与计划任务部署、桌面安装包定义及配置示例 | PowerShell、Inno Setup(ISS)、JSON、Markdown | -| `scripts/` | 项目构建、Windows 安装包、Linux deb/tar.gz 打包及本地启动脚本 | PowerShell、Shell | +| `scripts/` | 项目构建、版本递增、Windows PE 依赖检查及安装包、Linux deb 打包及本地启动脚本 | PowerShell、Shell、Python | | `tests/` | Python 桥接测试、三端集成测试及可选真机验证 | Python | | `docs/` | 协议、部署、验证及旧局域网桥接说明 | Markdown | | `config/` | 本地配置容器;`private/` 保存私有凭据等配置,已被 Git 忽略,不纳入发布包 | 环境变量文件等配置格式,无业务源码 | diff --git a/Cargo.lock b/Cargo.lock index f4f26e9..faa0e4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "ads-agent" -version = "0.2.0" +version = "0.2.1" dependencies = [ "ads-core", "ads-management", @@ -21,7 +21,7 @@ dependencies = [ [[package]] name = "ads-client" -version = "0.2.0" +version = "0.2.1" dependencies = [ "ads-core", "anyhow", @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "ads-core" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "bytes", @@ -51,7 +51,7 @@ dependencies = [ [[package]] name = "ads-management" -version = "0.2.0" +version = "0.2.1" dependencies = [ "ads-core", "anyhow", @@ -67,7 +67,7 @@ dependencies = [ [[package]] name = "ads-usb" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "clap", @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "adsctl" -version = "0.2.0" +version = "0.2.1" dependencies = [ "ads-core", "ads-management", diff --git a/Cargo.toml b/Cargo.toml index 86346d5..609193a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["crates/ads-core", "agent", "client", "usb", "crates/ads-management", resolver = "2" [workspace.package] -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MIT" diff --git a/README.md b/README.md index b04ee29..3885df6 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Windows 现支持可选的 [USB ADB 模拟](docs/windows-usb.md),默认网络 | 目录 | 作用 | 主要语言/格式 | | --- | --- | --- | +| `android_agent/` | 手机直接联网的 Android 设备端,Kotlin 传统 View、前台服务与 Rust JNI 网关;不申请运行时权限 | Kotlin、Rust、Gradle Kotlin DSL、XML、TOML | | `agent/` | 无界面多手机守护程序 ads-agent、独立监督进程、私有 IPC 和远程管理;兼容单设备参数;源码在 `src/` | Rust、TOML | | `ctl/` | adsctl 命令行管理端,本机/远程设备、配置、日志、重启及系统启动托管;源码在 `src/` | Rust、TOML | | `usb/` | 可选 ads-usb 本机虚拟 ADB USB 设备,提供回环 USB/IP、描述符和 ADB 帧适配;Windows 使用已签名 USBip 虚拟控制器,Linux 使用内核 vhci_hcd(CLI) | Rust、TOML | @@ -61,6 +62,7 @@ Windows 现支持可选的 [USB ADB 模拟](docs/windows-usb.md),默认网络 | 目录 | 输出 | 职责 | |---|---|---| | `server/` | `ads-server` / `ads-relay` | 控制中心:认证、注册、设备独占、信令、健康检查;独立中继:数据转发 | +| `android_agent/` | 手机直接联网的 Android 设备端,Kotlin 传统 View、前台服务与 Rust JNI 网关;不申请运行时权限 | Kotlin、Rust、Gradle Kotlin DSL、XML、TOML | | `agent/` | `ads-agent` | 远程电脑后台进程,主动注册设备、接通手机、断线重连 | | `client/` | `ads-client` | 本地后台进程,保持设备租约,提供本地端口,自动调用 `adb connect` | | `crates/ads-management/` | Agent 配置及管理协议、Windows 命名管道/Unix socket、私有文件与系统服务操作;源码在 `src/` | Rust、TOML | @@ -239,3 +241,6 @@ Flutter 管理中心已迁移 Cupertino UI,设备按电脑归属分组,支 每次新发布打包将版本号的补丁位增加 1(例如 0.2.0 → 0.2.1),同步 Cargo 工作区与锁文件、Avalonia、Flutter 和安装包版本。Windows 必须生成 Setup.exe,Linux 采用 deb 安装包;普通开发编译不增加版本。同一版本的 Windows/Linux 安装包只递增一次,另一平台使用复用版本选项。打包失败后重试复用已分配版本,避免重复递增。发布产物不包含私有凭据。 `scripts/release-version.py` 为共享版本分配脚本(Python)。Windows 使用 `scripts/build-installers.ps1` 自动递增并重建后端与桌面安装包;同一次发布的重试或第二平台使用 `-ReuseVersion`。Linux 使用 `bash scripts/build-linux-packages.sh` 自动递增,另一平台已分配版本时设置 `ADS_REUSE_VERSION=1`,须提供该版本重新构建的原生产物。 + + +Windows 发布精简:Avalonia 合并托管程序集、保留原生库;Flutter 源码插件静态链接 MSVC CRT。`scripts/check-windows-crt.py` 使用 Python 标准库检查 PE 直接及延迟导入,防止缺失运行库。安装升级清理应用根目录旧 DLL,保留配置和独立工具目录。 diff --git a/deploy/windows/desktop-installer.iss b/deploy/windows/desktop-installer.iss index dafcd5a..cf820c8 100644 --- a/deploy/windows/desktop-installer.iss +++ b/deploy/windows/desktop-installer.iss @@ -24,6 +24,9 @@ RestartApplications=no SetupLogging=yes [Tasks] Name: desktopicon; Description: "Create a desktop shortcut"; Flags: unchecked +[InstallDelete] +; Root DLLs are release payload only; remove obsolete runtime files before copying. +Type: files; Name: "{app}\*.dll" [Files] Source: "{#Source}\*"; DestDir: "{app}"; Excludes: "*.env,*.log,*.pdb,settings.json,agent.json,*.sock"; Flags: ignoreversion recursesubdirs createallsubdirs [Icons] diff --git a/desktop/Ads.Desktop/Ads.Desktop.csproj b/desktop/Ads.Desktop/Ads.Desktop.csproj index 1809b0c..cb079bb 100644 --- a/desktop/Ads.Desktop/Ads.Desktop.csproj +++ b/desktop/Ads.Desktop/Ads.Desktop.csproj @@ -1,4 +1,4 @@ - WinExenet8.0enableenable + 0.2.1WinExenet8.0enableenable diff --git a/desktop/Ads.Desktop/Program.cs b/desktop/Ads.Desktop/Program.cs index 3800704..9cc309b 100644 --- a/desktop/Ads.Desktop/Program.cs +++ b/desktop/Ads.Desktop/Program.cs @@ -6,6 +6,20 @@ internal static class Program [STAThread] public static void Main(string[] args) { + if (args.Contains("--package-check")) + { + // Exercise the actual published bundle without loading credentials or acquiring the UI lease. + BuildAvaloniaApp().SetupWithoutStarting(); + var folder=Path.Combine(Path.GetTempPath(),"ads-package-"+Guid.NewGuid().ToString("N")); + using var vm=new MainViewModel(folder,backgroundMonitoring:false,loadLocalCredentials:false); + var window=new MainWindow {DataContext=vm}; + using var done=new CancellationTokenSource(); + window.Show(); + Avalonia.Threading.DispatcherTimer.RunOnce(()=>{window.Close();done.Cancel();},TimeSpan.FromSeconds(2)); + Avalonia.Threading.Dispatcher.UIThread.MainLoop(done.Token); + Console.WriteLine("PACKAGE_CHECK_OK"); + return; + } if (!OperatingSystem.IsWindows()) { BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); return; } using var instance = new DesktopInstance(); Instance = instance; diff --git a/desktop/README.md b/desktop/README.md index 9620594..8403f18 100644 --- a/desktop/README.md +++ b/desktop/README.md @@ -94,3 +94,5 @@ USB 会话后端已按操作系统选择:Windows 使用已签名 USBip 控制 192.168.5.224 工程位于 `/home/tt/TongTongStudio/AndroidDeviceStreaming`,自包含发行目录为 `bin/desktop-linux-x64/`。已在 TT 的 X11 会话启动成功;已有 .NET 8.0.16 runtime 和 SDK 8.0.409 位于 `/home/tt/.dotnet`,SSH PATH 未包含此目录。工程要求 SDK 8.0.428,远程源码构建尚需安装该版本;自包含发行版无需安装 runtime。 桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。 + +Windows 自包含发布把托管程序集打包到主程序,保留原生图形 DLL 和独立 Rust/ADB/scrcpy 工具;不启用反射裁剪,不要求安装 .NET,也不将全部应用压为单文件。发布使用全新暂存目录。`Ads.Desktop.exe --package-check` 可在隔离配置、无设备连接和不占用正式客户端互斥锁的条件下创建窗口后退出,用于验证发布包。 diff --git a/docs/verification.md b/docs/verification.md index 298848e..3fadfae 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -63,3 +63,11 @@ Port cleanup follow-up: - 修复后的 Agent 已部署 Ubuntu-224,备份保留在原二进制旁。`phone-a9bbc18df94c` 通过公网 relay-1 被本地 ADB 识别并执行 shell;原离线虚拟 USB `ADS-phone-006f8b2ae57e` 已恢复 device,shell getprop ro.product.model 成功。临时网络 ADB 测试连接已断开。 - Rust ads-core 6 项测试、Avalonia 22 项测试、Flutter 27 项测试通过,Flutter analyze 无问题。 - 两桌面端新增打开日志目录;Avalonia 同步电脑名、电脑排序、固定高度刷新指示与按天滚动日志。安装位置采用 TongTongStudio,保留既有私有配置和日志路径。 + +### 0.2.1 Windows DLL 精简发布 + +- Avalonia 根目录 DLL 从 211 降至 4:托管程序集使用 .NET bundle,保留 3 个原生图形/字体库与 Rust 工具必需的 vcruntime140.dll;没有启用反射裁剪或把 Rust、ADB、scrcpy 合并进主程序。 +- Flutter 根目录 DLL 从 15 降至 6:保留引擎、4 个插件和 Rust 所需的 vcruntime140.dll;宿主、包装库及源码插件采用静态 MSVC CRT。PE 直接/延迟导入扫描按实际闭包补齐运行库,不再整目录复制 VC Redist。 +- Avalonia 实际发布包 `--package-check` 成功创建窗口并退出,未读取正式凭据、未建立设备连接;Flutter 6 个根目录 DLL 可由 Windows 加载。Avalonia 22 项、Flutter 27 项测试通过。未在全新 Windows 虚拟机执行本轮完整安装回归。 +- 新版 Windows Setup 安装包和 Linux amd64 Avalonia/Agent deb 均为 0.2.1,带 SHA256 校验。Linux deb 元数据已验证;Flutter Linux 宿主仍未实现,本轮未生成 Flutter Linux 包。 +- DLL 数量指安装目录根目录;tools/scrcpy 自带库保持完整。打包减少散落 DLL,不承诺安装程序体积同步减小。 diff --git a/flutter_manager/README.md b/flutter_manager/README.md index 84fd45d..f11278e 100644 --- a/flutter_manager/README.md +++ b/flutter_manager/README.md @@ -135,3 +135,5 @@ USB ADB 连续 3 轮监控缺失(约 9 秒)、USB 后端退出或 scrcpy 以 工作台和 Agent 页的刷新指示器使用固定高度占位。Agent 发现列表保留到切换主机;旧后端不支持 devices_discover 时提示同步更新 CLI 和 Agent。`test/daily_log_test.dart` 验证跨天、大小滚动、保留及脱敏,`test/cupertino_layout_test.dart` 验证电脑名和刷新布局不移位。 桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。 + +Windows 宿主、Flutter C++ 包装库和源码插件统一使用静态 MSVC CRT,保留 Flutter 引擎及插件 DLL。安装打包使用 `scripts/check-windows-crt.py`(Python 标准库 PE 导入及延迟导入检查),只附带实际需要的 MSVC 运行库及其传递依赖,缺失则拒绝发布;Rust 工具仍需的运行库不会被误删。 diff --git a/flutter_manager/pubspec.yaml b/flutter_manager/pubspec.yaml index 015396d..4eb8cb1 100644 --- a/flutter_manager/pubspec.yaml +++ b/flutter_manager/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 0.2.1+2 environment: sdk: ^3.14.0 diff --git a/flutter_manager/windows/CMakeLists.txt b/flutter_manager/windows/CMakeLists.txt index 2901667..5575e2c 100644 --- a/flutter_manager/windows/CMakeLists.txt +++ b/flutter_manager/windows/CMakeLists.txt @@ -1,5 +1,7 @@ # Project-level configuration. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.15) +# Apply static CRT consistently to runner, Flutter wrappers and source plugins. +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") project(ads_manager LANGUAGES CXX) # The name of the executable created for the application. Change this to change diff --git a/scripts/build-desktop.ps1 b/scripts/build-desktop.ps1 index 2033c9d..9bcce0a 100644 --- a/scripts/build-desktop.ps1 +++ b/scripts/build-desktop.ps1 @@ -1,16 +1,27 @@ param( - [string]$Runtime = 'win-x64', + [ValidateSet('win-x64','win-arm64','linux-x64','linux-arm64','osx-x64','osx-arm64')][string]$Runtime = 'win-x64', [switch]$FrameworkDependent ) $ErrorActionPreference = 'Stop' $projectRoot = Split-Path $PSScriptRoot -Parent $outputDirectory = Join-Path $projectRoot "bin/desktop-$Runtime" $selfContained = if ($FrameworkDependent) { 'false' } else { 'true' } +# Publish to a fresh staging folder so obsolete runtime DLLs cannot survive upgrades. +$stage = Join-Path $projectRoot ('bin/publish-desktop-' + [guid]::NewGuid().ToString('N')) +$publishOptions=@() +if ($Runtime.StartsWith('win-') -and -not $FrameworkDependent) { + $publishOptions=@('-p:PublishSingleFile=true','-p:IncludeNativeLibrariesForSelfExtract=false','-p:EnableCompressionInSingleFile=true','-p:DebugType=embedded') +} Push-Location (Join-Path $projectRoot 'desktop') try { - dotnet publish Ads.Desktop -c Release -r $Runtime --self-contained $selfContained -o $outputDirectory --nologo + dotnet publish Ads.Desktop -c Release -r $Runtime --self-contained $selfContained -o $stage --nologo @publishOptions if ($LASTEXITCODE -ne 0) { throw 'Desktop publish failed' } } finally { Pop-Location } +if (Test-Path -LiteralPath $outputDirectory) { + if (Get-ChildItem -LiteralPath $outputDirectory -Recurse -File -Filter '*.env') { throw 'Private env file in release directory; refusing to replace it' } + Remove-Item -LiteralPath $outputDirectory -Recurse -Force +} +Move-Item -LiteralPath $stage -Destination $outputDirectory $suffix = if ($Runtime.StartsWith('win-')) { '.exe' } else { '' } foreach ($toolName in @('ads-client', 'ads-usb', 'adsctl', 'ads-agent')) { $client = Join-Path $projectRoot ('bin/' + $toolName + $suffix) diff --git a/scripts/build-flutter.ps1 b/scripts/build-flutter.ps1 index b9dc55d..cd34d60 100644 --- a/scripts/build-flutter.ps1 +++ b/scripts/build-flutter.ps1 @@ -6,6 +6,10 @@ try { flutter build windows --release -t lib/main.dart if ($LASTEXITCODE -ne 0) { throw 'Flutter publish failed' } } finally { Pop-Location } +if (Test-Path -LiteralPath $output) { + if (Get-ChildItem -LiteralPath $output -Recurse -File -Filter '*.env') { throw 'Private env file in release directory; refusing to replace it' } + Remove-Item -LiteralPath $output -Recurse -Force +} New-Item -ItemType Directory -Force -Path $output | Out-Null Copy-Item -Path (Join-Path $projectRoot 'flutter_manager/build/windows/x64/runner/Release/*') -Destination $output -Recurse -Force foreach ($name in @('ads-client','ads-agent','adsctl','ads-usb')) { diff --git a/scripts/build-installers.ps1 b/scripts/build-installers.ps1 index 4846338..d56dbbf 100644 --- a/scripts/build-installers.ps1 +++ b/scripts/build-installers.ps1 @@ -32,13 +32,11 @@ foreach ($name in @('Avalonia','Flutter')) { if ($LASTEXITCODE) { throw "$name build failed" } } $source=Join-Path $root "bin/$folder" - if ($name -eq 'Flutter') { - $crt=Get-ChildItem "$env:ProgramFiles/Microsoft Visual Studio/2022/*/VC/Redist/MSVC/*/x64/Microsoft.VC143.CRT" -Directory -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1 - if ($crt) { Copy-Item -Path (Join-Path $crt.FullName '*.dll') -Destination $source -Force } - foreach ($runtime in @('msvcp140.dll','vcruntime140.dll','vcruntime140_1.dll')) { - if (-not (Test-Path -LiteralPath (Join-Path $source $runtime))) { throw "Missing redistributable C++ runtime: $runtime" } - } - } + $crt=Get-ChildItem "$env:ProgramFiles/Microsoft Visual Studio/2022/*/VC/Redist/MSVC/*/x64/Microsoft.VC143.CRT" -Directory -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1 + $crtArgs=@((Join-Path $PSScriptRoot 'check-windows-crt.py'),$source) + if ($crt) { $crtArgs+=@('--runtime-dir',$crt.FullName) } + & python @crtArgs + if ($LASTEXITCODE) { throw 'Unresolved C++ runtime dependency in release payload' } & (Join-Path $PSScriptRoot 'copy-windows-usb-driver.ps1') -Destination $source if (-not (Test-Path -LiteralPath (Join-Path $source 'ads-usb.exe'))) { Copy-Item -LiteralPath (Join-Path $root 'bin/ads-usb.exe') -Destination $source } foreach ($file in @($exe,'adsctl.exe','ads-agent.exe','ads-client.exe','tools/scrcpy/adb.exe','tools/scrcpy/scrcpy.exe')) { diff --git a/scripts/check-windows-crt.py b/scripts/check-windows-crt.py new file mode 100644 index 0000000..70bfb4f --- /dev/null +++ b/scripts/check-windows-crt.py @@ -0,0 +1,82 @@ +"""Resolve only required app-local MSVC runtime DLLs, or fail if missing. +Uses PE import and delay-import tables; no third-party Python modules required. +""" +import re +import struct +import sys +from pathlib import Path + + +def imports(path): + data = path.read_bytes() + if data[:2] != b'MZ': + raise ValueError(f'Not PE: {path}') + pe = struct.unpack_from('