Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

[VSCode] Unable to select iOS and Android devices #192

Description

@davidortinau

I can run Mac Catalyst, but when choosing Android and iOS I cannot select a device. The error is the same both times:

Screen Shot 2021-06-15 at 9 13 01 PM

Log (Extension Host) reports:

[2021-06-15 21:12:21.324] [exthost] [info] ExtensionService#_doActivateExtension Clancey.comet-debug {"startup":false,"extensionId":{"value":"Clancey.comet-debug","_lower":"clancey.comet-debug"},"activationEvent":"onStartupFinished"}
[2021-06-15 21:12:21.324] [exthost] [info] ExtensionService#loadCommonJSModule file:///Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension
[2021-06-15 21:12:40.232] [exthost] [error] TypeError: Cannot read property 'map' of undefined
	at MobileProjectManager.<anonymous> (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:22125:22)
	at Generator.next (<anonymous>)
	at fulfilled (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:21852:58)
	at processTicksAndRejections (internal/process/task_queues.js:93:5) dotnetmobile.selectDevice
[2021-06-15 21:12:41.936] [exthost] [error] TypeError: Cannot read property 'map' of undefined
	at MobileProjectManager.<anonymous> (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:22125:22)
	at Generator.next (<anonymous>)
	at fulfilled (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:21852:58)
	at processTicksAndRejections (internal/process/task_queues.js:93:5) dotnetmobile.selectDevice
[2021-06-15 21:13:32.444] [exthost] [error] TypeError: Cannot read property 'devices' of undefined
	at MobileProjectManager.<anonymous> (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:22161:51)
	at Generator.next (<anonymous>)
	at fulfilled (/Users/dmo/.vscode/extensions/clancey.comet-debug-0.3.7/dist/extension.js:21852:58)
	at processTicksAndRejections (internal/process/task_queues.js:93:5) dotnetmobile.selectDevice

I'm running macOS Monterey and .NET 6 Preview 5.

I can run iOS from CLI just fine.

Activity

  1. angelobreuer commented on Jun 20, 2021

    @angelobreuer

    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-debug tool which is normally located at c:\Users\[username]\.vscode\extensions\clancey.comet-debug-0.3.7\src\mobile-debug\bin\Debug\net472\mobile-debug.exe.

    image
    (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.

    image

    For iOS it runs mobile-debug.exe util -c ios-devices.

    image

    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-debug program here.

    The actual error on Android occurs in AndroidSdk.cs:102:

    https://github.com/Clancey/vscode-comet/blob/d5b8b059e02e6a400f39b5336c76adf52ab6a69a/src/mobile-debug/AndroidSdk.cs#L100-L106

    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 avd

    After 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 device

    To 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 avd to 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-devices again 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:

    image

    image

    It also works on a physical device now:

    Screenshot_20210620-091327

    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 -l which 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-debug program with util -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:

    image

    On an OS X machine, you may get probably a similar error with the correct path.


    Hope I could help!

  2. pente1986 commented on Jun 14, 2022

    @pente1986

    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 ~/.zshrc

    export 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:1

    Running 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: 512M

    Android 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=true

    openjdk: microsoft-openjdk11 (installed with brew. version 11 Required by Maui)
    dotnet-sdk version: 6.0.300
    OS: macOS Monterey (12.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions