Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: TypeError if no device exists. (run android) #6056

Closed
twoco opened this issue Nov 5, 2022 · 4 comments
Closed

bug: TypeError if no device exists. (run android) #6056

twoco opened this issue Nov 5, 2022 · 4 comments
Labels
cli type: bug A confirmed bug report

Comments

@twoco
Copy link

twoco commented Nov 5, 2022

> ionic capacitor run android

? Which device would you like to target? (Use arrow keys)
TypeError: Cannot read properties of undefined (reading 'value')

We could show "No device found". instead of accessing an undefined variable (error).

cap v3.4.3, Windows 10

@jcesarmobile
Copy link
Member

I can't reproduce.
ionic capacitor run android will run npx cap run android internally, which will then call npx native-run android --list --json to get the list of available emulators and devices.
The thing is npx native-run android --list --json will create a new emulator if there aren't any.
Might be there when the "cannot read properties of undefined" happens.

Can you provide your native-run and @ionic/cli versions?

ionic --version
npx native-run --version

and then run npx native-run android --list --json and see if it returns at least an emulator?

@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Nov 7, 2022
@twoco
Copy link
Author

twoco commented Nov 7, 2022

I run ionic as npm script. So my workspace version is used. It's 6.19.0 (same with 6.20.3). npx native-run is 1.7.0.

Script: ionic capacitor run android

Ok as I see now the error only appears then hit enter when no list appears.

? Which device would you like to target?
(empty list)
(enter)
TypeError: Cannot read properties of undefined (reading 'value')

Without knowing the code, I think there is no if-condition or optional chaning of the selected entry. The selected item variable is just used direactly and tries to read ts value.

$ npx native-run android --list --json

without any device/emulator connected

{
  "devices": [],
  "virtualDevices": [],
  "errors": [
    {
      "error": "No suitable API installation found. Use --sdk-info to reveal missing packages and other issues.",
      "code": "ERR_UNSUITABLE_API_INSTALLATION"
    }
  ]
}

device connected

{
  "devices": [
    {
      "platform": "android",
      "model": "BLABLABLA",
      "sdkVersion": "28",
      "id": "BLABLABLA"
    }
  ],
  "virtualDevices": [],
  "errors": [
    {
      "error": "No suitable API installation found. Use --sdk-info to reveal missing packages and other issues.",
      "code": "ERR_UNSUITABLE_API_INSTALLATION"
    }
  ]
}

Weird error. I already tried --sdk-info but it seems that this arg does not exist.

I wonder what library calls value of the selected entry (in this case undefined).
But anyway, I would not show "Which device would you like to target?" if the list is empty. Or show "[No device found]" below.

Another issue is to automatically select the connected device. Espacially if only one device is connected. In my list I only have one device. And sometimes I run this command and forget to select it. ^^ But I remember the early Capacitor days where you needed to run the project in Android Studio. Glad to see that Capacitor works over CLI now (like Cordova) to run on device. 👍

Anyway this issue described here is not critical. I just thought I could report this minor issue to improve it a bit.

Btw. I don't understand why this command "will create a new emulator". It would also be wrong behavior to do so.

Long story short: We just need to know where the value is accessed and simply check nullish (undefined) here. And as bonus show "No device found." Or just close this issue and live with this error as it is harmless. It's just a bit less professional. ^^

@Ionitron Ionitron removed the needs reply needs reply from the user label Nov 7, 2022
@jcesarmobile
Copy link
Member

The problem is your android SDK is not correctly installed, it’s missing some packages.
Capacitor CLI should forward the error from native-run instead of showing the empty list.
https://github.com/ionic-team/native-run/wiki/Android-Errors#err_unsuitable_api_installation

the --sdk-info parameter is for native-run command, it doesn’t exist on capacitor nor ionic

@ionitron-bot
Copy link

ionitron-bot bot commented Dec 15, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cli type: bug A confirmed bug report
Projects
None yet
Development

No branches or pull requests

3 participants