Reduce Windows DLL dependencies and package release 0.2.1

This commit is contained in:
tongtong committed 2026-11-13 12:24:24 +08:00
1 parent fc0edd433f
commit efaf16de18
17 files changed
+152 -20

No files matched your search

+2 -1
View File
@@ -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 忽略,不纳入发布包 | 环境变量文件等配置格式,无业务源码 |
Generated
+6 -6
View File
@@ -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",
+1 -1
View File
@@ -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"
+5
View File
@@ -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,保留配置和独立工具目录。
+3
View File
@@ -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]
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>WinExe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<PropertyGroup><Version>0.2.1</Version><OutputType>WinExe</OutputType><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<ItemGroup><PackageReference Include="Avalonia.Desktop" Version="11.3.8"/><PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.8"/><PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/></ItemGroup>
<ItemGroup><AvaloniaResource Include="Assets/**"/></ItemGroup></Project>
+14
View File
@@ -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;
+2
View File
@@ -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` 可在隔离配置、无设备连接和不占用正式客户端互斥锁的条件下创建窗口后退出,用于验证发布包。
+8
View File
@@ -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,不承诺安装程序体积同步减小。
+2
View File
@@ -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 工具仍需的运行库不会被误删。
+1 -1
View File
@@ -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
+3 -1
View File
@@ -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$<$<CONFIG:Debug>:Debug>")
project(ads_manager LANGUAGES CXX)
# The name of the executable created for the application. Change this to change
+13 -2
View File
@@ -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)
+4
View File
@@ -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')) {
+4 -6
View File
@@ -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" }
}
}
$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')) {
+82
View File
@@ -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('<I', data, 60)[0]
if data[pe:pe+4] != b'PE\0\0':
raise ValueError(f'Invalid PE: {path}')
count, optional_size = struct.unpack_from('<H12xH', data, pe+6)
optional = pe+24
plus = struct.unpack_from('<H', data, optional)[0] == 0x20b
directories = optional + (112 if plus else 96)
image_base = struct.unpack_from('<Q' if plus else '<I', data, optional+(24 if plus else 28))[0]
sections = []
for i in range(count):
size, rva, raw_size, raw = struct.unpack_from('<IIII', data, optional+optional_size+i*40+8)
sections.append((rva, max(size, raw_size), raw))
def offset(rva):
for base, size, raw in sections:
if base <= rva < base+size:
return raw+rva-base
raise ValueError(f'Unmapped RVA in {path}')
result = []
for index, stride in ((1, 20), (13, 32)):
rva, size = struct.unpack_from('<II', data, directories+index*8)
if not rva:
continue
start = offset(rva)
for at in range(start, start+size, stride):
row = data[at:at+stride]
if not any(row):
break
name = struct.unpack_from('<I', row, 12 if index == 1 else 4)[0]
if index == 13 and not (struct.unpack_from('<I', row)[0] & 1):
name -= image_base
at_name = offset(name)
result.append(data[at_name:data.index(b'\0', at_name)].decode('ascii').lower())
return result
def main():
import argparse
import shutil
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('folder', type=Path)
parser.add_argument('--runtime-dir', type=Path)
args = parser.parse_args()
folder = args.folder
pending = sorted([*folder.glob('*.exe'), *folder.glob('*.dll')])
if not pending:
raise ValueError('No Windows binaries to validate')
checked = set()
runtime = set()
while pending:
binary = pending.pop()
if binary.name.lower() in checked:
continue
checked.add(binary.name.lower())
for name in imports(binary):
if not re.match(r'(msvcp|vcruntime|vccorlib|concrt)\d', name):
continue
runtime.add(name)
target = folder / name
if not target.exists():
provider = next((p for p in args.runtime_dir.glob('*.dll') if p.name.lower() == name), None) if args.runtime_dir else None
if provider is None:
raise SystemExit(f'Missing MSVC runtime: {binary.name} requires {name}')
shutil.copyfile(provider, target)
pending.append(target)
print(f'PASS: {len(checked)} root PE files checked; required app-local CRT: {", ".join(sorted(runtime)) or "none"}')
if __name__ == '__main__':
main()
+1 -1
View File
@@ -14,7 +14,7 @@ def update(root, reuse=False):
version = f"{major}.{minor}.{patch + 1}"
changes = {cargo: content.replace(f'version = "{old}"', f'version = "{version}"', 1)}
lock = root / "Cargo.lock"
changes[lock] = re.sub(r'(name = "ads-[^"\n]+"\nversion = ")[^"]+("\n)', lambda m: m[1] + version + m[2], lock.read_text(encoding="utf-8"))
changes[lock] = re.sub(r'(name = "(?:ads-[^"\n]+|adsctl)"\nversion = ")[^"]+("\n)', lambda m: m[1] + version + m[2], lock.read_text(encoding="utf-8"))
pub = root / "flutter_manager/pubspec.yaml"
changes[pub] = re.sub(r'^version: ([^\n]+)', lambda m: f"version: {version}+{int(m[1].split('+')[1]) + 1}", pub.read_text(encoding="utf-8"), flags=re.M)
project = root / "desktop/Ads.Desktop/Ads.Desktop.csproj"