修复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
相关推荐
我命由我123458 小时前
Kotlin 开发 - lateinit 关键字
android·java·开发语言·kotlin·android studio·android-studio·android runtime
一起搞IT吧8 小时前
Android性能系列专题理论之十:systrace/perfetto相关指标知识点细节含义总结
android·嵌入式硬件·智能手机·性能优化
舟遥遥娓飘飘13 小时前
Nexus4CC 手机电脑同步claude code对话部署教程(基于linux系统)
linux·智能手机·电脑
STER labo15 小时前
mysql配置环境变量——(‘mysql‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件解决办法)
数据库·mysql·adb
一起搞IT吧15 小时前
Android性能系列专题理论之十一:block IO问题分析思路
android·嵌入式硬件·智能手机·性能优化
开开心心就好16 小时前
近200个工具的电脑故障修复合集
安全·智能手机·pdf·电脑·consul·memcache·1024程序员节
꯭爿꯭巎꯭17 小时前
星界智联APP下载手机版
智能手机
sjmaysee19 小时前
CentOS7安装Mysql5.7(ARM64架构)
adb·架构
@大迁世界1 天前
14个你现在必须关闭的 iOS 26 设置,不然手机很快被它榨干
macos·ios·智能手机·objective-c·cocoa
AtOR CUES1 天前
MySQL——表操作及查询
android·mysql·adb