0-TEST-CONNECT.BAT 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. @echo off
  2. chcp 65001 >nul
  3. setlocal enabledelayedexpansion
  4. echo ========================================
  5. echo Test ADB Connection
  6. echo ========================================
  7. echo.
  8. REM Get the directory where this batch file is located
  9. set "SCRIPT_DIR=%~dp0"
  10. set "PROJECT_ROOT=%SCRIPT_DIR%.."
  11. REM Read ADB path from config.js using PowerShell
  12. echo [0/6] Reading ADB path from config.js...
  13. for /f "delims=" %%i in ('powershell -Command "$content = Get-Content '%PROJECT_ROOT%\config.js' -Raw; $content = $content -replace 'module\.exports\s*=\s*', ''; $content = $content -replace ';', ''; $content = $content.Trim(); $json = $content | ConvertFrom-Json; $adbPath = $json.'adb-path'; if ($adbPath) { Write-Output ($adbPath.TrimEnd('\') + '\adb.exe') } else { Write-Output 'adb' }"') do set "ADB_PATH=%%i"
  14. if "%ADB_PATH%"=="" set "ADB_PATH=adb"
  15. echo Using ADB: %ADB_PATH%
  16. echo.
  17. echo Please enter the last two digits of the IP address:
  18. set /p IP_LAST_TWO="Last two digits (e.g., 0.15): "
  19. if "%IP_LAST_TWO%"=="" (
  20. echo Error: IP address cannot be empty
  21. pause
  22. exit /b 1
  23. )
  24. set DEVICE_IP=192.168.%IP_LAST_TWO%
  25. set DEVICE_PORT=5555
  26. set DEVICE_ADDRESS=%DEVICE_IP%:%DEVICE_PORT%
  27. echo.
  28. echo Connecting to %DEVICE_ADDRESS%...
  29. echo.
  30. echo [1/6] Check if ADB is available...
  31. "%ADB_PATH%" version >nul 2>&1
  32. if errorlevel 1 (
  33. echo Error: ADB not found at: %ADB_PATH%
  34. echo Please check config.js and ensure ADB path is correct
  35. pause
  36. exit /b 1
  37. )
  38. echo ADB is available
  39. echo.
  40. echo [2/6] Test network connectivity (ping %DEVICE_IP%)...
  41. ping -n 2 %DEVICE_IP% >nul 2>&1
  42. if errorlevel 1 (
  43. echo Cannot ping %DEVICE_IP%
  44. echo Possible reasons: Phone and computer not on same network, or phone is off
  45. echo.
  46. ) else (
  47. echo Network connectivity OK
  48. echo.
  49. )
  50. echo [3/6] Check if port %DEVICE_PORT% is open...
  51. powershell -Command "Test-NetConnection -ComputerName %DEVICE_IP% -Port %DEVICE_PORT% -InformationLevel Quiet" >nul 2>&1
  52. if errorlevel 1 (
  53. echo Port %DEVICE_PORT% may not be open or blocked by firewall
  54. echo.
  55. ) else (
  56. echo Port %DEVICE_PORT% is accessible
  57. echo.
  58. )
  59. echo [4/6] Disconnect old connection (if any)...
  60. "%ADB_PATH%" disconnect %DEVICE_ADDRESS% >nul 2>&1
  61. timeout /t 1 /nobreak >nul
  62. echo Attempting to connect %DEVICE_ADDRESS%...
  63. "%ADB_PATH%" connect %DEVICE_ADDRESS%
  64. set CONNECT_RESULT=%ERRORLEVEL%
  65. echo.
  66. if %CONNECT_RESULT% equ 0 (
  67. echo Connection command completed
  68. echo.
  69. timeout /t 2 /nobreak >nul
  70. ) else (
  71. echo.
  72. echo Connection failed (Error code: %CONNECT_RESULT%)
  73. echo.
  74. echo ========================================
  75. echo Troubleshooting Steps:
  76. echo ========================================
  77. echo 1. Enable "Developer Options" on phone
  78. echo - Settings ^> About phone ^> Tap "Build number" 7 times
  79. echo.
  80. echo 2. Enable "USB debugging"
  81. echo - Settings ^> Developer options ^> USB debugging
  82. echo.
  83. echo 3. Enable "Wireless debugging" or "Network ADB debugging"
  84. echo - Settings ^> Developer options ^> Wireless debugging
  85. echo - Or: Settings ^> Developer options ^> Network ADB debugging
  86. echo - Confirm port is %DEVICE_PORT%
  87. echo.
  88. echo 4. If phone doesn't have "Wireless debugging" option, try:
  89. echo a) Connect phone to computer via USB
  90. echo b) Run: 0-ENABLE-TCPIP.BAT
  91. echo c) Unplug USB, then run this script again
  92. echo.
  93. echo 5. Check if phone and computer are on same Wi-Fi network
  94. echo.
  95. echo 6. Disable phone firewall or allow ADB through firewall
  96. echo.
  97. )
  98. echo [5/6] Check device list...
  99. echo.
  100. "%ADB_PATH%" devices
  101. echo.
  102. echo ========================================
  103. echo Test completed
  104. echo ========================================
  105. pause