android - Visual Studio 2022 17.4.3 .NET MAUI Android 模拟不起作用

标签 android .net visual-studio-2022 maui

我正在尝试使用 .NET MAUI 在 VS 2022 中的 Android 模拟器中运行我的第一个 Hello World: https://learn.microsoft.com/en-us/dotnet/maui/get-started/first-app?view=net-maui-6.0&tabs=vswin&pivots=devices-android 但它并没有发生。
我从 VS 17.4.0 和随之而来的 Android Oreo 开始,慢慢升级到 VS 17.4.3 和 Android Pixel_5_-_api_31
这是我在 Android 模拟器中运行演示时的 VS 输出:

    Build started...
1>------ Build started: Project: MauiApp2, Configuration: Debug Any CPU ------
Starting emulator pixel_5_-_api_31 ...
Couldn't find emulator pixel_5_-_api_31. Resetting...
1>C:\Users\iliab\source\repos\MauiApp2\MauiApp2\MauiApp2.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
C:\Program Files (x86)\Android\android-sdk\emulator\emulator.EXE -netfast -accel on -avd pixel_5_-_api_31 -prop monodroid.avdname=pixel_5_-_api_31
1>MauiApp2 -> C:\Users\iliab\source\repos\MauiApp2\MauiApp2\bin\Debug\net6.0-android\MauiApp2.dll
1>C:\Users\iliab\source\repos\MauiApp2\MauiApp2\MauiApp2.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
1>C:\Users\iliab\source\repos\MauiApp2\MauiApp2\MauiApp2.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
1>C:\Users\iliab\source\repos\MauiApp2\MauiApp2\MauiApp2.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
1>C:\Users\iliab\source\repos\MauiApp2\MauiApp2\MauiApp2.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
1>Done building project "MauiApp2.csproj".
Emulator pixel_5_-_api_31 cannot be started.
1>Done building project "MauiApp2.csproj".
2>------ Deploy started: Project: MauiApp2, Configuration: Debug Any CPU ------
2>Starting deployment to pixel_5_-_api_31 ...
2>Starting emulator pixel_5_-_api_31 ...
2>C:\Program Files (x86)\Android\android-sdk\emulator\emulator.EXE -netfast -accel on -avd pixel_5_-_api_31 -prop monodroid.avdname=pixel_5_-_api_31
2>Emulator pixel_5_-_api_31 cannot be started.
2>Deploy failed
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:10.323 ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
========== Elapsed 00:10.323 ==========

这是在命令行中运行该模拟器的输出:

C:\Windows\system32>"C:\Program Files (x86)\Android\android-sdk\emulator\emulator.EXE" -netfast -accel on -avd pixel_5_-_api_31 -prop monodroid.avdname=pixel_5_-_api_31
INFO    | Android emulator version 31.2.10.0 (build_id 8420304) (CL:N/A)
WARNING | unexpected system image feature string, emulator might not function correctly, please try updating the emulator.
WARNING | unexpected '-prop' value ('monodroid.avdname=pixel_5_-_api_31'), only 'qemu.*' properties are supported
INFO    | added library vulkan-1.dll
INFO    | configAndStartRenderer: setting vsync to 60 hz
INFO    | Sending adb public key [QAAAAD+oxNJBuNwzjKU7lcaaJrj0gRjZ1mbzSQsVnvMoZzlKGzBM9CgZ555S+ypB1CtZj/ub0IcTs6aZB9qWqwLhghxk0gIwyy4U7TmQP6ABi2csYoWW0CWdApfpgRjAklO0P/jjQTlMT/XG5npQ0nO5P4ExKHI+QCYKW7KxFY5rIdNTh6s3teNA05ajx7T6ryZTg/vJSTgrlFxaW22gva4//QLTCxBfLARbd5a3GqwegMMeNxB25Kf5wWt9kB8N53FRkv2WZ0lDcF5LaKfDjGy1Y/EUpgpYBFLRjlKQznw/15ClbTL0uB79+x76xtBgveFkXgOg7hrI0+s9xXNt9SrOZOzYsvG2gzKu6MySNMslazSmghm3oYDIF3iGPJgusAmMADfFkGLwWLVDe6+6s5Y1pNgcJk3AkaN5wLcl0VnMelUJ+fTljQm0goxw66uT8EL01pYCy1L2caf/OlNYVzfmwlGM0Z5KOASm0fdJT4dTzQh/iYXQOcOt4cgvKG6OI5A76VNPsUC9rpj9t/tSZT0AlcXafIJYJQ7IFKIwymFzlCQQr6S5jl4So+SJ/7T4HWd5wVAgA1FC4pWr96fLCyxPqWbNpKqw01ml2SBh6vewEd/Cfhp/r8HmKimKuTnpzj+uCgchLKRS+n3QN4U7FzMOji9OXCvmfccwfW98YPMYhSUdqlThigEAAQA= @unknown]
INFO    | Rootcanal has  been activated.
HAX is working and emulator runs in fast virt mode.
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local
INFO    | Advertising in: C:\Users\iliab\AppData\Local\Temp\avd\running\pid_22892.ini
C:\Program Files (x86)\Android\android-sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: error while loading state for instance 0x0 of device 'goldfish_pipe'
INFO    | Deleting snapshot default_boot
VCPU shutdown request
VCPU shutdown request
INFO    | Shutting down gRPC endpoint
INFO    | Shutting down gRPC endpoint
INFO    | Closing down rootcanal.

这些是 Android SDK Manager 中当前打开的各种复选框:

enter image description here enter image description here enter image description here

如果未选中 HAXM 加速器,它就会挂起(将其放置过夜)。在这两种情况下,它都会使模拟器窗口闪烁一秒钟,然后将其关闭。

最佳答案

我有预感,这个问题与我的真实 Windows 机器上的一些硬件短缺有关,Android 试图从中接管资源 - 内存磁盘空间、摄像头、声音等。
因此,我选择了最基本的模拟器,然后尽可能地禁用或限制其硬件。还禁用 FastBoot 以阻止其保存快照和使用磁盘空间

enter image description here

我还尝试清理尽可能多的磁盘。每次我尝试某些操作时,即使我稍后卸载它,可用磁盘空间也会不断减少。
例如,当您添加然后删除 Android 设备时,删除的设备会在 C:\Program Files 中留下一个目录( x86)\Android\android-sdk\system-images 可能非常大。

然后,我更改了项目上 Android 目标中的最小目标 Android 框架,以匹配我选择的模拟器。另请注意 .Net 6 作为目标运行时。即使对于 Windows 目标,.Net 7 对我来说仍然是一个问题。 enter image description here

当然,请确保您的 SDK 管理器已选中复选标记,以匹配您选择的设备的 API 级别。
enter image description here enter image description here 终于成功了。

关于android - Visual Studio 2022 17.4.3 .NET MAUI Android 模拟不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74816563/

相关文章:

Android 模拟器不向下滚动

java - 过滤器列表在空结果时不会改变

c# - ApiController 扩展方法 - 无法访问 ResponseMessage

c# - 使用 LINQ 将集合拆分为 `n` 部分?

android - 对话框关闭时隐藏软输入键盘

android - Onbackpressed 关闭应用程序登录后不关闭应用程序

.net - 将行颜色绑定(bind)到 MVVM 中的属性(取决于行中的数据)

c++ - 更新到 Visual Studio 17.4.0 会产生与 TLS 相关的链接器错误

c# - 如何删除或关闭编辑器窗口中内嵌显示的错误?

c# - 建议使用 webapplicationbuilder.configuration 而不是 configureappconfiguration