fix: restore automatic startup of local ADB server
This commit is contained in:
1 parent
f826bdf3b0
commit
49873e7f05
9 files changed
+211
-23
No files matched your search
+16
-5
@@ -126,12 +126,23 @@ function Update-EnvironmentPath {
|
||||
|
||||
function Start-LocalAdbServer {
|
||||
if (Test-CommandExists "adb") {
|
||||
$adbErrorPreference = $ErrorActionPreference
|
||||
try {
|
||||
$origSocket = $env:ADB_SERVER_SOCKET
|
||||
Remove-Item Env:\ADB_SERVER_SOCKET -ErrorAction SilentlyContinue
|
||||
& adb start-server 2>$null | Out-Null
|
||||
if ($origSocket) { $env:ADB_SERVER_SOCKET = $origSocket }
|
||||
} catch {}
|
||||
# Windows PowerShell 5.1 wraps native stderr in ErrorRecord objects.
|
||||
# ADB prints normal daemon-start messages there, so inspect its exit code.
|
||||
$ErrorActionPreference = "Continue"
|
||||
# Explicit options ignore inherited remote-server environment settings.
|
||||
$adbOutput = & adb -H localhost -P 5037 start-server 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " [警告] 本机 ADB 服务启动失败(退出码 $LASTEXITCODE)。" -ForegroundColor Yellow
|
||||
Write-Host ($adbOutput | Out-String).Trim() -ForegroundColor Yellow
|
||||
Write-Host " [操作] 请检查 ADB 安装、端口占用或安全软件拦截;本机设备暂不可用。" -ForegroundColor Yellow
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [警告] 本机 ADB 服务启动异常:$_" -ForegroundColor Yellow
|
||||
} finally {
|
||||
$ErrorActionPreference = $adbErrorPreference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user