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

Win11/Parallels/VS2022下.NET8 MAUI Android调试失败求助

问题描述
  • 环境:macOS Sonoma 14.2(Intel),通过Parallels运行Windows系统及Visual Studio 2022 17.8.3,使用macOS本地Android模拟器
  • 需求:从Windows端VS启动.NET 8 MAUI Android应用,在macOS模拟器上进行调试
  • 异常情况:应用可成功部署至模拟器,但调试时卡在启动页;不附加调试器时应用能正常启动;已尝试调整RuntimeIdentifiers配置、修改快速部署设置,问题仍存在;Android Studio中创建的原生Android应用可正常调试
调试会话日志
Start debugging Android application ...
> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.mauiapp2/crc6452f1ea43b9adf718.MainActivity"
> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.mauiapp2/crc6452f1ea43b9adf718.MainActivity }
[nyname.mauiapp2] Late-enabling -Xcheck:jni
[nyname.mauiapp2] Using CollectorTypeCC GC.
[nyname.mauiapp2] Unexpected CPU variant for x86: x86_64.
[nyname.mauiapp2] Known variants: atom, sandybridge, silvermont, goldmont, goldmont-plus, tremont, kabylake, default
[CompatibilityChangeReporter] Compat change id reported: 171979766; UID 10144; state: ENABLED
[CompatibilityChangeReporter] Compat change id reported: 242716250; UID 10144; state: ENABLED
[ApplicationLoaders] Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar
[ApplicationLoaders] Returning zygote-cached class loader: /system_ext/framework/androidx.window.sidecar.jar
[ziparchive] Unable to open '/data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/base.dm': No such file or directory
[ziparchive] Unable to open '/data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/base.dm': No such file or directory
[nativeloader] Configuring clns-6 for other apk /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64:/data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/base.apk!/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.companyname.mauiapp2
[GraphicsEnvironment] Currently set values for:
[GraphicsEnvironment] angle_gl_driver_selection_pkgs=[]
[GraphicsEnvironment] angle_gl_driver_selection_values=[]
[GraphicsEnvironment] ANGLE GameManagerService for com.companyname.mauiapp2: false
[GraphicsEnvironment] com.companyname.mauiapp2 is not listed in per-application setting
[GraphicsEnvironment] Neither updatable production driver nor prerelease driver is supported.
[debug-app-helper] Checking if libmonodroid was unpacked to /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64/libmonodroid.so
[debug-app-helper] Native libs extracted to /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64, assuming application/android:extractNativeLibs == true
[debug-app-helper] Setting up for DSO lookup in app data directories
[debug-app-helper] Added filesystem DSO lookup location: /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64
[debug-app-helper] Using runtime path: /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64
[debug-app-helper] checking directory: `/data/user/0/com.companyname.mauiapp2/files/.__override__/lib`
[debug-app-helper] directory does not exist: `/data/user/0/com.companyname.mauiapp2/files/.__override__/lib`
[debug-app-helper] Checking whether Mono runtime exists at: /data/user/0/com.companyname.mauiapp2/files/.__override__/libmonosgen-2.0.so
[debug-app-helper] Checking whether Mono runtime exists at: /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64/libmonosgen-2.0.so
[debug-app-helper] Mono runtime found at: /data/app/~~hCLu-bitDpG3yh9Qu3dMAQ==/com.companyname.mauiapp2-t43XgUbfffXZqelJx7K7ww==/lib/x86_64/libmonosgen-2.0.so
[nyname.mauiapp2] Attempt to remove non-JNI local reference
[DOTNET] JNI_OnLoad: JNI_OnLoad in pal_jni.c
[DOTNET] GetOptionalClassGRef: optional class com/android/org/conscrypt/OpenSSLEngineImpl was not found
[monodroid] Creating public update directory: `/data/user/0/com.companyname.mauiapp2/files/.__override__`
[nyname.mauiapp2] Attempt to remove non-JNI local reference
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=10.0.2.2:52981,embedding=1,timeout=1702668782
问题分析与解决方案

从调试日志和环境来看,主要排查以下几个方向:

1. 跨系统调试的网络连通性问题

日志显示调试器尝试连接10.0.2.2:52981,这个地址是Android模拟器默认指向宿主机的地址,但因为Windows运行在Parallels虚拟机中,模拟器的宿主机是macOS而非Windows,导致Windows端VS无法通过这个地址连接到模拟器的调试端口。

  • 解决步骤:
    • 把Parallels的网络模式切换为「桥接网络」,让Windows和macOS处于同一局域网段。
    • 获取macOS的本地IP(终端执行ifconfig查看),修改MAUI项目的调试配置,将调试器连接地址改为这个IP,而非默认的10.0.2.2。
    • 临时关闭macOS防火墙,测试是否是防火墙阻止了调试端口的连接。

2. CPU架构不兼容

日志中出现Unexpected CPU variant for x86: x86_64,说明模拟器是x86_64架构,但MAUI项目的运行时标识可能未正确适配该架构。

  • 解决步骤:
    • 打开项目的.csproj文件,确保RuntimeIdentifiers节点包含android-x64,示例:
      <RuntimeIdentifiers>android-x64;android-arm64</RuntimeIdentifiers>
      
    • 删除项目的bin和obj文件夹,清理缓存后重新生成项目,再尝试调试。

3. 调试器超时时间不足

日志中的调试器参数包含timeout=1702668782,对应超时时间可能过短,导致调试器还未完成初始化就超时卡住。

  • 解决步骤:
    • 在Visual Studio中,进入「工具」-「选项」-「调试」-「Android」,找到调试超时设置,将数值调大(比如设置为300秒)。

4. Mono调试器组件问题

虽然日志显示找到了Mono运行时,但可能存在版本不匹配或组件损坏的情况。

  • 解决步骤:
    • 将Visual Studio升级到最新稳定版本(比如17.9.x),同时确保.NET 8 SDK安装了最新补丁包。
    • 在Visual Studio的「工具」-「获取工具和功能」中,重新安装或修复Android开发 workload,确保Mono相关组件完整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 18:18:15