Xamarin.Forms android 模拟器无法在 Visual Studio 中启动

问题描述 投票:0回答:1

我在 Visual Studio 中从 Android 设备管理器启动 Android 模拟器 Nexus 5 时遇到问题,我尝试启用 Hyper-V、AEHD 和 HAXM,但没有成功。由于某种原因,我在“adb devices”中看不到模拟器,而且当我启动它时,我无法从 Android 设备管理器中停止它。

我尝试按照 Microsoft 进行故障排除,但没有帮助,我无法通过 CMD“emulator -avd avd_name [ {-option [value]} … ]”启动模拟器,我也尝试重新安装 SDK,但没有成功帮助。当我开始使用该模拟器进行调试时,它刚刚开始部署并出现进度条,但它冻结在那里,我等了 1 小时但什么也没发生。你知道我应该如何解决这个问题吗?

这是日志文件的开头:

[23-07-13 16.15.38.75] Android Device Manager version 17.6.0.76-HEAD@aca9c0a
[23-07-13 16.15.38.75] Build date: 12.7.2023. 14.24.53
[23-07-13 16.15.38.75] Operating system: Windows 10 v10.0.19045 (Windows 10 Pro; Microsoft Windows 10 v10.0.19045 (Windows 10 Pro; 64-bit)), 64-bit
[23-07-13 16.15.38.75] Run arguments: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Xamarin\AndroidDeviceManager\AndroidDevices.exe" android-registry=SOFTWARE\Xamarin\VisualStudio\17.0_4a684485\Android mono-android-path="C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android" log-path="<USER_HOME>\AppData\Local\Xamarin\Logs\17.0" vs-pid=12052 vs_version=17.6 p=7cbf9e92-6396-4a99-9c0c-dc5b99175070 telemetry_session="{\"IsOptedIn\":true,\"HostName\":\"Dev14\",\"AppInsightsInstrumentationKey\":\"f144292e-e3b2-4011-ac90-20e5c03fbce5\",\"AsimovInstrumentationKey\":\"AIF-312cbd79-9dbb-4c48-a7da-3cc2a931cb70\",\"CollectorApiKey\":\"f3e86b4023cc43f0be495508d51f588a-f70d0e59-0fb0-4473-9f19-b4024cc340be-7296\",\"AppId\":1001,\"UserId\":\"1526062c-98b6-45f0-a17a-9b12d89a4411\",\"Id\":\"6dedc337-fbee-4b74-af8a-f463976f4f11\",\"ProcessStartTime\":638248613028280328,\"SkuName\":\"VS_Community\",\"VSExeVersion\":\"17.6.33829.357\",\"BucketFiltersToEnableWatsonForFaults\":[{\"AdditionalProperties\":[],\"Id\":\"53126781-21df-4995-bac8-6c850c7c1efb\",\"WatsonEventType\":\"VisualStudioMemWatson\",\"BucketParameterFilters\":[\"(?i)perfwatsonstarvation\",null,null,null,null,null,null,null,null,null]}],\"BucketFiltersToAddDumpsToFaults\":[{\"AdditionalProperties\":[{\"Key\":\"DumpType\",\"Value\":\"Heap\"}],\"Id\":\"e9940337-2ead-49ca-8069-098d308bf8c0\",\"WatsonEventType\":\"VisualStudioNonFatalErrors2\",\"BucketParameterFilters\":[null,null,\"vs.fault.faulttest\",null,null,null,null,null,null,null]}]}" 
[23-07-13 16.15.38.80] [AppInfo] Detected Android SDK path: C:\Program Files (x86)\Android\android-sdk
[23-07-13 16.15.38.83] --- Device Manager started
[23-07-13 16.15.38.93] Window_LocationChanged
    [23-07-13 16.15.39.03] No Android SDK instance matching the 'C:\Program Files (x86)\Android\android-sdk' path
    [23-07-13 16.15.39.56] Xamarin manifest base URL: https://aka.ms/xamarin/sdkmanifest/
    [23-07-13 16.15.39.57] Parsing: platform tools
    [23-07-13 16.15.39.58] Parsing: tools
    [23-07-13 16.15.39.58] No elements of this kind found
    [23-07-13 16.15.39.58] Parsing: cmdline-tools
    [23-07-13 16.15.39.58] Parsing: build tools
    [23-07-13 16.15.39.58] Parsing: emulators
    [23-07-13 16.15.39.58] Parsing: NDK
    [23-07-13 16.15.39.58] Parsing: LLDB
    [23-07-13 16.15.39.58] No elements of this kind found
    [23-07-13 16.15.39.58] Parsing: patchers
    [23-07-13 16.15.39.58] Parsing: platforms
    [23-07-13 16.15.39.58] Parsing: system images
    [23-07-13 16.15.39.60] Parsing: addons
    [23-07-13 16.15.39.60] Parsing: extras
    [23-07-13 16.15.39.60] Detecting Android SDK in 'C:\Program Files (x86)\Android\android-sdk'
    [23-07-13 16.15.39.61] Detecting component Android SDK Platform-Tools r34.0.3 in directory 'C:\Program Files (x86)\Android\android-sdk\platform-tools'
    [23-07-13 16.15.39.61]   Found revision 34.0.3 on the system
    [23-07-13 16.15.39.61] Detecting component Android SDK Platform-Tools r34.0.1 in directory 'C:\Program Files (x86)\Android\android-sdk\platform-tools'
    [23-07-13 16.15.39.61]   Found revision 34.0.3 on the system
    [23-07-13 16.15.39.61] Detecting component Android SDK Platform-Tools r33.0.3 in directory 'C:\Program Files (x86)\Android\android-sdk\platform-tools'
    [23-07-13 16.15.39.62]   Found revision 34.0.3 on the system
    [23-07-13 16.15.39.62] Detecting component Android SDK Platform-Tools r33.0.2 in directory 'C:\Program Files (x86)\Android\android-sdk\platform-tools'
    [23-07-13 16.15.39.62]   Found revision 34.0.3 on the system
    [23-07-13 16.15.39.62] Detecting component Android SDK Command-line Tools r7.0 in directory 'C:\Program Files (x86)\Android\android-sdk\cmdline-tools/7.0'
    [23-07-13 16.15.39.62]   Found revision 7.0 on the system
    [23-07-13 16.15.39.62] Component Android SDK Command-line Tools r6.0 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Command-line Tools r5.0 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 33.0.2 r33.0.2 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 33.0.1 r33.0.1 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 33 r33.0.0 not present on the system
    [23-07-13 16.15.39.62] Detecting component Android SDK Build-Tools 32 r32.0.0 in directory 'C:\Program Files (x86)\Android\android-sdk\build-tools/32.0.0'
    [23-07-13 16.15.39.62]   Found revision 32.0.0 on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 31 r31.0.0 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 30.0.3 r30.0.3 not present on the system
    [23-07-13 16.15.39.62] Component Android SDK Build-Tools 30.0.2 r30.0.2 not present on the system
    [23-07-13 16.15.39.62] Detecting component Android Emulator r32.1.14 in directory 'C:\Program Files (x86)\Android\android-sdk\emulator'
    [23-07-13 16.15.39.62]   Found revision 32.1.14 on the system
    [23-07-13 16.15.39.62] Detecting component Android Emulator r32.1.14 in directory 'C:\Program Files (x86)\Android\android-sdk\emulator'
    [23-07-13 16.15.39.62]   Found revision 32.1.14 on the system
    [23-07-13 16.15.39.62] Detecting component Android Emulator r32.1.14 in directory 'C:\Program Files (x86)\Android\android-sdk\emulator'
    [23-07-13 16.15.39.62]   Found revision 32.1.14 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r22.1.7171670 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r22.0.7026061 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r21.4.7075529 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r21.3.6528147 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r21.2.6472646 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r21.1.6352462 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r21.0.6113669 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r20.1.5948944 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.62] Detecting component NDK r20.0.5594570 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.62]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r19.2.5345600 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r19.0.5232133 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r18.1.5063045 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r17.2.4988734 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r16.1.4479499 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Detecting component NDK r14.1.3816874 in directory 'C:\Program Files (x86)\Android\android-sdk\ndk-bundle'
    [23-07-13 16.15.39.63]   Found revision 20.1.5948944 on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 22.1.7171670 r22.1.7171670 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 22.0.7026061 r22.0.7026061 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 21.4.7075529 r21.4.7075529 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 21.3.6528147 r21.3.6528147 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 21.2.6472646 r21.2.6472646 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 21.1.6352462 r21.1.6352462 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 21.0.6113669 r21.0.6113669 not present on the system
    [23-07-13 16.15.39.63] Component NDK (Side by side) 20.1.5948944 r20.1.5948944 not present on the system
[23-07-13 16.15.39.63] Component NDK (Side by side) 20.0.5594570 r20.0.5594570 not present on the system

这是日志文件的结尾:

[23-07-13 16.23.13.92] Going to stop nexus_5_-_api_23
[23-07-13 16.23.13.92] [AvdInfo.Stop] Enter
[23-07-13 16.23.13.93] [EmulatorManager.Stop] Enter. EmulatorName:
[23-07-13 16.23.13.93] AVDStatusToButtonTextConverter [Convert]Stop
[23-07-13 16.23.13.93] AVDStatusToButtonTextConverter [Convert]Stop
[23-07-13 16.23.13.93] AVDStatusToButtonTextConverter [Convert]Stop
[23-07-13 16.23.13.93] [EmulatorManager.Stop] AVDNamenexus_5_-_api_23
[23-07-13 16.23.13.93] [GetEmulatorNameRunningAvd]:+ avdNamenexus_5_-_api_23
[23-07-13 16.23.13.93] [ProcessStartInfoAsInvoker] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "devices"
[23-07-13 16.23.13.98] [EmulatorManager.Stop] EmulatorName is: 
[23-07-13 16.23.13.98] [ProcessStartInfoAsInvoker] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "devices"
[23-07-13 16.23.14.02] [GetEmulatorNameRunningAvd]:+ avdNamenexus_5_-_api_23
[23-07-13 16.23.14.02] [ProcessStartInfoAsInvoker] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "devices"
[23-07-13 16.23.14.49] [ProcessStartInfoAsInvoker] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "devices"
[23-07-13 16.23.14.58] [GetEmulatorNameRunningAvd]:+ avdNamenexus_5_-_api_24
[23-07-13 16.23.14.58] [ProcessStartInfoAsInvoker] Executing command: "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" "devices"

当我通过 CMD 启动它时,我得到这个:

Microsoft Windows [Version 10.0.19045.3208]
(c) Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>emulator -avd nexus_5_-_api_23
INFO    | Android emulator version 32.1.14.0 (build_id 10330179) (CL:N/A)
INFO    | Found systemPath C:\Program Files (x86)\Android\android-sdk\system-images\android-23\google_apis\x86\
INFO    | Storing crashdata in: C:\Users\Miroslav\AppData\Local\Temp\\AndroidEmulator\emu-crash.db, detection is enabled
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
INFO    | IPv4 server found: 109.122.99.130
C:\Program Files (x86)\Android\android-sdk\emulator\qemu\windows-x86_64\qemu-system-i386.exe: -usbdevice tablet: '-usbdevice' is deprecated, please use '-device usb-...' instead
HAX is working and emulator runs in fast virt mode.
C:\Program Files (x86)\Android\android-sdk\emulator\qemu\windows-x86_64\qemu-system-i386.exe: -drive format=raw,file=cat:C:\Users\Miroslav\.android\avd\nexus_5_-_api_23.avd\system.img.qcow2|C:\Users\Miroslav\.android\avd\nexus_5_-_api_23.avd\userdata-qemu.img.qcow2|C:\Users\Miroslav\.android\avd\nexus_5_-_api_23.avd\vendor.img.qcow2: cat driver can't open backing file C:\Users\Miroslav\.android\avd\nexus_5_-_api_23.avd\vendor.img.qcow2

我在该路径上找不到vendor.img.qcow2

我找到了一种通过右键单击 .Droid 项目文件来启动模拟器的方法,在“属性”部分,我看到“使用设置为 Anroid 8.1 (Oreo) 的 Android 版本进行编译”,并且我为 Nexus 5 手机下载了基于 x86 架构的模拟器,但我仍然有在模拟器上显示任何内容的问题,我只是有空白屏幕。我还获得了该模拟器的vendor.img.qcow2文件,因此我可以将其复制到其他版本上,然后它们就可以工作,但也会显示黑屏。

现在,当我输入“adb devices”命令时,我得到:

List of devices attached
emulator-5554   offline

我在 CMD 中有这个:

D:\Xamarin\xamarin-forms-book-samples\Chapter02\Hello\Hello\Hello>emulator -avd nexus_5_-_api_27
INFO    | Android emulator version 32.1.14.0 (build_id 10330179) (CL:N/A)
INFO    | Found systemPath C:\Program Files (x86)\Android\android-sdk\system-images\android-27\google_apis_playstore\x86\
INFO    | Storing crashdata in: C:\Users\Miroslav\AppData\Local\Temp\\AndroidEmulator\emu-crash.db, detection is enabled
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
INFO    | IPv4 server found: 109.122.99.130
C:\Program Files (x86)\Android\android-sdk\emulator\qemu\windows-x86_64\qemu-system-i386.exe: -usbdevice tablet: '-usbdevice' is deprecated, please use '-device usb-...' instead
HAX is working and emulator runs in fast virt mode.
dsound: Could not initialize DirectSoundCapture
dsound: Reason: No sound driver is available for use, or the given GUID is not a valid DirectSound device ID
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO    | Advertising in: C:\Users\Miroslav\AppData\Local\Temp\avd\running\pid_17036.ini
Attempt to initialize voice without DirectSoundCapture object
Attempt to initialize voice without DirectSoundCapture object
Failed to create voice `adc'
debugging xamarin android-emulator adb device-manager
1个回答
0
投票

您可以从以下几个方面来排查问题:

1.删除模拟器并创建一个新的模拟器,然后重试。

2.如果问题仍然存在,请重新检查您是否正确设置了Android SDK。

有关更多信息,请查看文档:为 Xamarin.Android 设置 Android SDK

3.尝试修复你的视觉工作室。

更多信息请查看文档:修复 Visual Studio

© www.soinside.com 2019 - 2024. All rights reserved.