You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2022更新后Jdwp连接失败,Android模拟器调试受阻求助

VS2022 17.9.4更新后Android模拟器调试失败(端口8100被系统占用)

问题描述

使用Visual Studio 2022开发Android应用,更新至17.9.4版本后,模拟器可正常启动,但应用始终卡在Waiting for debugger状态,无法完成调试连接。

错误信息

模拟器端提示

Waiting for debugger
Application XXX(xxx) is waiting for the debugger to attach.

Visual Studio调试输出

warning: Could not connect Jdwp. Mono.AndroidTools.AdbException: cannot bind listener: cannot bind to 127.0.0.1:8100: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
   at Mono.AndroidTools.Util.AggregateAsyncResult.CheckError(CancellationToken token) in D:\a\_work\1\s\External\androidtools\Mono.AndroidTools\Util\AggregateAsyncResult.cs:line 72
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.AndroidTools.Debugging.DebuggingExtensions.<ConnectJdwpAsync>d__7.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\DebuggingExtensions.cs:line 183
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.AndroidTools.Debugging.DebuggingExtensions.<StartWithDebuggingAsync>d__1.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\DebuggingExtensions.cs:line 61

端口占用情况

已确认端口8100被Windows系统进程占用:

System  4   IPv4 unspecified    8100    TCP Not allowed, not restricted 

已尝试的解决方案

  • 创建新的模拟器
  • 执行adb root; adb reverse tcp:8080 tcp:8080命令
  • 重启电脑
  • 重新安装Android Emulator Hypervisor Driver和Android模拟器工具

需求

希望修改JDWP使用的端口,或找到其他无需切换到真实设备的解决方案。


解决方案

方法1:修改Visual Studio的JDWP调试端口

通过注册表指定自定义JDWP端口:

  1. 打开注册表编辑器(运行regedit)
  2. 导航到路径:HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\17.0_<你的VS实例ID>\Xamarin\Android
    • 若路径不存在,手动创建Xamarin\Android项
  3. 新建DWORD(32位)值,命名为DebugPort
  4. 设置值为未被占用的端口(例如8101,选择十进制)
  5. 重启Visual Studio后重新调试

方法2:临时释放端口8100(谨慎操作)

若必须使用8100端口,可尝试:

  1. 以管理员权限打开命令提示符
  2. 执行net stop winnat停止相关网络服务
  3. 启动模拟器并调试
  4. 调试完成后执行net start winnat恢复服务

注意:此操作可能影响其他网络连接,需谨慎执行

方法3:ADB手动转发JDWP端口(临时应急)

  1. 启动模拟器后,执行adb devices获取设备ID
  2. 执行adb shell ps | grep <应用包名>获取应用进程ID
  3. 执行adb -s <设备ID> forward tcp:<自定义端口> jdwp:<应用进程ID>
  4. 在Visual Studio调试设置中手动指定该自定义端口连接

方法4:回退Visual Studio版本

若上述方法均无效,可回退到17.9.3版本,等待官方修复端口冲突问题。


内容的提问来源于stack exchange,提问作者Jakob Aagesen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 08:48:39