Repository navigation
[VSCode] Unable to select iOS and Android devices #192
Description
Activity
Why the error occurs (Android)
Like you, I got the following error in the VSCode extension log window:
[2021-06-20 08:37:28.569] [exthost] [error] TypeError: Cannot read property 'devices' of undefined at MobileProjectManager.<anonymous> (c:\Users\[...]\.vscode\extensions\clancey.comet-debug-0.3.7\dist\extension.js:22161:51) at Generator.next (<anonymous>) at fulfilled (c:\Users\[...]\.vscode\extensions\clancey.comet-debug-0.3.7\dist\extension.js:21852:58) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:93:5) dotnetmobile.selectDevice
The vscode extension for Comet makes use of the
mobile-debugtool which is normally located atc:\Users\[username]\.vscode\extensions\clancey.comet-debug-0.3.7\src\mobile-debug\bin\Debug\net472\mobile-debug.exe.
(I've added the console.log statements myself to get the path and arguments in the Developer Console of VSCode for further investigation)For android, it runs
mobile-debug.exe util -c android-devices.For iOS it runs
mobile-debug.exe util -c ios-devices.If you run these commands manually with the command line you'll get an error, the extension does ignore the error and tries to parse the empty JSON result, and fails when mapping the value.
You can find the source code of the
mobile-debugprogram here.The actual error on Android occurs in AndroidSdk.cs:102:
It tries to find the device data for the emulator which was shown as connected in my case when running
adb devices -l. It fails to query the device name (L79) and then fails because the name was null (L102).
Solution (Android)
In my case, my system somehow had an emulator registered in AVDManager that did not even exist on disk (in a fresh installation).
Note that I can only provide the Windows command because I do not have an OS X system at hand.
To verify, run the following command:
C:\Program Files (x86)\Android\android-sdk\tools\bin>avdmanager list avdAfter some debug console output, I've got the following:
The following Android Virtual Devices could not be loaded: Name: pixel_2_pie_9_0_-_api_28 Path: C:\Users\[username]\.android\avd\pixel_2_pie_9_0_-_api_28.avd Error: Google pixel_2 no longer exists as a deviceTo delete this device, run
C:\Program Files (x86)\Android\android-sdk\tools\bin>avdmanager delete avd -n pixel_2_pie_9_0_-_api_28.You can ignore any errors because it tries to delete the emulator from the disk, which does not even exist.
Now run the following command again:
C:\Program Files (x86)\Android\android-sdk\tools\bin>avdmanager list avdto verify that the emulator was removed:C:\Program Files (x86)\Android\android-sdk\tools\bin>avdmanager list avd Available Android Virtual Devices:Now run
c:\Users\[username]\.vscode\extensions\clancey.comet-debug-0.3.7\src\mobile-debug\bin\Debug\net472\mobile-debug.exe util -c android-devicesagain to verify the program works correctly now:{"id":"82a0c173-956a-407b-848f-56e363122246","command":"android-devices","response":[]}(The GUID can differ)
Now start up your emulator, restart Visual Studio Code (should work without a restart but safe is safe), select net6.0-android, and click on "Select device". Now it should work:
It also works on a physical device now:
Alternative Solution (Android)
-
Create emulator (I use command line because I do not have Android Studio installed)
(- Install (Open)JDK8 (or else you will get an error with avdmanager).)
(- If you had another JDK installed, change your JAVA_HOME to point to the new (old) installation.)- To create the emulator run: C:\Program Files (x86)\Android\android-sdk\tools\bin>avdmanager.bat create avd -n "AndroidEmulator" -k system-images;android-30;google_apis;x86
-
Startup emulator
- C:\Program Files (x86)\Android\android-sdk\tools>emulator @androidemulator
- If you get the following error: "PANIC: Missing emulator engine program for 'x86' CPU." (which happened in my case):
- Set ANDROID_SDK to "C:\Program Files (x86)\Android\android-sdk"
- ADD the following to PATH: "C:\Program Files (x86)\Android\android-sdk\platform-tools", "C:\Program Files (x86)\Android\android-sdk\emulator", and "C:\Program Files (x86)\Android\android-sdk\tools" (order is important here).
- Run the first command again.
-
Ensure the emulator is running
- Run adb devices -l
- Ensure you have something like: "emulator-5554 device [...]"
-
Now it should work, I assume avdmanager recognized that there was an emulator shown in
adb devices -lwhich does not really exist (I do not know the exact internals of the Android SDK).
Why the error occurs (iOS)
I tried to run the
mobile-debugprogram withutil -c ios-devices. It fails because it tries to find XCode on my machine which cannot be installed. When you debug the mobile-debug program, I encountered the following error:On an OS X machine, you may get probably a similar error with the correct path.
Hope I could help!
-
Hi! I'm having a similar error here.
I'm getting an error only when I try to select a virtual android
device (ios-device selection and debugging works).When I click on "Select a Device" throws the error:
Cannot read properties of undefined (reading 'map').
The Android Virtual Device is running (started from VDM of Android Studio)
when I click on "Select a Device".Next is the output of the commands mentioned in previous comments.
Running mobile-debug:
% cd ~/.vscode/extensions/clancey.comet-debug-0.3.16/src/mobile-debug/bin/Debug/net6.0/
% dotnet mobile-debug.dll util -c android-devices
{"id":"[ID]","command":"android-devices","error":"Could not find adb"}I added to PATH the path to platform-tools folder, but the error is still there.
added to ~/.zshrcexport PATH=/Users/[username]/Library/Android/sdk/platform-tools:$PATH
Running adb:
% cd ~/Library/Android/sdk/platform-tools
% ./adb devices -l
List of devices attached
emulator-5554 offline transport_id:1Running avdmanager:
% cd ~/Library/Android/sdk/cmdline-tools/latest/bin
% ./avdmanager list avd
Available Android Virtual Devices:
Name: Pixel_3a_API_31
Device: pixel_3a (Google)
Path: /Users//.android/avd/Pixel_3a_API_31.avd
Target: Google Play (Google Inc.)
Based on: Android 12.0 (S) Tag/ABI: google_apis_playstore/x86_64
Skin: pixel_3a
Sdcard: 512MAndroid Studio info:
Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 18, 2022
Runtime version: 11.0.12+0-b1504.28-7817840 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.4
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 16
Registry: external.system.auto.import.disabled=trueopenjdk: microsoft-openjdk11 (installed with brew. version 11 Required by Maui)
dotnet-sdk version: 6.0.300
OS: macOS Monterey (12.4)






I can run Mac Catalyst, but when choosing Android and iOS I cannot select a device. The error is the same both times:
Log (Extension Host) reports:
I'm running macOS Monterey and .NET 6 Preview 5.
I can run iOS from CLI just fine.