修复Android studio的adb无法连接手机问题

复制下面的内容到一个文本txt里面然后把里面的Android studio路径和sdk路径改成你自己的,然后改成把.txt改成bat

右键管理员运行

复制代码
@echo off
REM Deep Fix for "Couldn't terminate the existing process" error
REM This script will completely reset ADB and device connection

echo ============================================
echo     DEEP ADB FIX - Process Termination Error
echo ============================================
echo.

set "ADB=E:\IDE\android-sdk\platform-tools\adb.exe"

REM Step 1: Force kill all ADB and related processes
echo [1/8] Force killing all processes...
taskkill /F /IM adb.exe 2>nul
taskkill /F /IM adb.exe /T 2>nul
taskkill /F /IM studio64.exe 2>nul
taskkill /F /IM java.exe 2>nul
taskkill /F /IM javaw.exe 2>nul
timeout /t 3 >nul
echo      Done!
echo.

REM Step 2: Kill ADB server multiple times to ensure it's dead
echo [2/8] Ensuring ADB server is completely stopped...
"%ADB%" kill-server 2>nul
timeout /t 2 >nul
"%ADB%" kill-server 2>nul
timeout /t 2 >nul
echo      Done!
echo.

REM Step 3: Delete ALL ADB cache and temp files
echo [3/8] Deleting all ADB cache and locks...
rmdir /S /Q "%USERPROFILE%\.android\cache" 2>nul
rmdir /S /Q "%USERPROFILE%\.android\build-cache" 2>nul
del /F /Q "%USERPROFILE%\.android\adbkey" 2>nul
del /F /Q "%USERPROFILE%\.android\adbkey.pub" 2>nul
del /F /Q "%USERPROFILE%\.android\*.lock" 2>nul
del /F /Q "%TEMP%\adb*.tmp" 2>nul
echo      Cache cleared!
echo.

REM Step 4: Reset USB drivers
echo [4/8] Resetting USB connection...
echo      Please unplug your phone now!
echo      Press any key after unplugging...
pause >nul
echo.
echo      Now plug your phone back in
echo      Press any key after plugging in...
pause >nul
echo      USB reset done!
echo.

REM Step 5: Start ADB with specific port
echo [5/8] Starting ADB on clean port...
"%ADB%" -P 5037 start-server
timeout /t 3 >nul
echo      ADB started!
echo.

REM Step 6: Force reconnect devices
echo [6/8] Force reconnecting devices...
"%ADB%" reconnect 2>nul
"%ADB%" reconnect device 2>nul
timeout /t 2 >nul
echo      Reconnection attempted!
echo.

REM Step 7: Kill app on device
echo [7/8] Attempting to kill app on device...
"%ADB%" shell am force-stop com.example.myapplication 2>nul
"%ADB%" shell pm clear com.example.myapplication 2>nul
echo      App processes cleared!
echo.

REM Step 8: Final device check
echo [8/8] Final device status:
echo ============================================
"%ADB%" devices -l
echo.
"%ADB%" get-state 2>nul
echo ============================================

echo.
echo Fix completed! Now try:
echo 1. In Android Studio: File -^> Invalidate Caches and Restart
echo 2. After restart, try running the app again
echo.
pause
相关推荐
老六ip加速器2 小时前
手机ip隔离方法
tcp/ip·智能手机·php
gamers20 小时前
rock linux 9 安装mysql 5.7.44
linux·mysql·adb
雨声不在20 小时前
使用android studio分析cpu开销
android·ide·android studio
独行soc21 小时前
2025年渗透测试面试题总结-67(题目+回答)
网络·python·安全·web安全·网络安全·adb·渗透测试
sibylyue1 天前
MySQLTransactionRollbackException
adb
wanhengidc1 天前
手机云服务是什么意思?
运维·网络·安全·游戏·智能手机
vxtkjzxt8881 天前
手机群控软件的核心本质与技术实现
智能手机
傲琪电子1 天前
傲琪人工合成石墨片:破解智能手机散热困境的创新解决方案
智能手机·材料工程
快乐觉主吖1 天前
adb的常用命令
adb