ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

`ionic capacitor run android` does not allow selection of device, then crashes

Open diesieben07 opened this issue 4 years ago • 9 comments

Description: After updating to Capacitor 3 ionic capacitor run android now attempts to directly launch the App on a device instead of simply opening Android Studio. The device selection fails. First ? Which device would you like to target? (Use arrow keys) is shown. If any arrow key is pressed, the (Use arrow keys) text disappears. Pressing enter produces the output

TypeError: Cannot read property 'value' of undefined

and nothing further happens.

Steps to Reproduce:

  • Run ionic capacitor run android in a Capacitor 3 project.

Output:

xxx@xxx:~/XXXXXXXX$ ionic capacitor run android --verbose
  ionic:lib Terminal info: { ci: false, shell: '/bin/bash', tty: true, windows: false } +0ms
  ionic:lib CLI global options: { _: [ 'capacitor', 'run', 'android' ], help: null, h: null, verbose: true, quiet: null, interactive: true, color: true, confirm: null, json: null, project: null, '--': [] } +2ms
  ionic:lib:project Project type from config: @ionic/angular (angular) +0ms
  ionic:lib:project Project details: { context: 'app', type: 'angular', errors: [], configPath: '/home/xxx/xxx/ionic.config.json' } +0ms
  ionic Context: { binPath: '/home/xxx/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli/bin/ionic', libPath: '/home/xxx/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli', execPath: '/home/xxx/xxx/xxx/xxx', version: '6.16.3' } +0ms
  ionic:lib:integrations:capacitor Getting config with Capacitor CLI: [ 'config', '--json' ] +0ms
  ionic:lib:integrations:capacitor Could not get config from Capacitor CLI (probably old version) +267ms
  ionic:commands:capacitor:run Getting native targets for 'android' with Capacitor CLI: [ 'run', 'android', '--list', '--json' ] +0ms
? Which device would you like to target? 
TypeError: Cannot read property 'value' of undefined

My ionic info:


Ionic:

   Ionic CLI                     : 6.16.3 (/home/xxx/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.6
   @angular-devkit/build-angular : 0.1102.11
   @angular-devkit/schematics    : 11.2.11
   @angular/cli                  : 11.2.11
   @ionic/angular-toolkit        : 3.1.1

Capacitor:

   Capacitor CLI      : 3.1.1
   @capacitor/android : 3.1.1
   @capacitor/core    : 3.1.1
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.4.0

System:

   NodeJS : v14.17.0 (/home/xxx/.nvm/versions/node/v14.17.0/bin/node)
   npm    : 6.14.13
   OS     : Linux 5.4

diesieben07 avatar Jul 16 '21 07:07 diesieben07

I am seeing this on macOS as well, but only in Android Studio. Works fine in IntelliJ or Terminal.

Ionic:

   Ionic CLI                     : 6.16.3 (/opt/homebrew/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.11
   @angular-devkit/build-angular : 12.1.2
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 12.1.2
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI      : 3.1.1
   @capacitor/android : 3.1.1
   @capacitor/core    : 3.1.1
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.4.0

System:

   NodeJS : v14.17.1 (/opt/homebrew/Cellar/node@14/14.17.1/bin/node)
   npm    : 6.14.13
   OS     : macOS Big Sur

mikelhamer avatar Jul 16 '21 21:07 mikelhamer

I found out that this was caused by a native-run failure. The ionic CLI does not handle error-output from native-run gracefully, instead simply falling into the above described buggy state. Any errors produced by native-run should be relayed to the command line.

diesieben07 avatar Aug 10 '21 07:08 diesieben07

Well! I was facing the same issue, tried running ionic capacitor run android -l --verbose and the device option started to show up.

wakqasahmed avatar Aug 25 '21 08:08 wakqasahmed

I found out that this was caused by a native-run failure. The ionic CLI does not handle error-output from native-run gracefully, instead simply falling into the above described buggy state. Any errors produced by native-run should be relayed to the command line.

What was the solution?

donnydg4 avatar Oct 21 '21 04:10 donnydg4

In my case the problem with native-run was that I had the wrong Android SDK, which caused it to error and quit. The Ionic CLI didn't relay the error message to the command line.

diesieben07 avatar Oct 21 '21 11:10 diesieben07

does anyone know how to solve it?

Rithik805 avatar Apr 06 '22 14:04 Rithik805

coz i am facing the same error

Rithik805 avatar Apr 06 '22 14:04 Rithik805

does anyone know how to solve it?

For me issue was in installed api version 21. After deleting 21 and 32 api from android studio and installing 31 api on virtual device i was able to select my virtual device in capacitor list. You could do the same but try other older api (if you need) e.g. 25. In my case i had unsupported api error inside native-run. After my above actions native-run showed my devices without any errors

vulnerabbity avatar Apr 27 '22 11:04 vulnerabbity

I did some research If using capacitor the cli tries to run capacitor run android --list --json which gets devices probably from avdmanager. I ran this command on my project directory, I recivied this output:

[fatal] native-run failed with errors

  	ERR_UNSUPPORTED_API_LEVEL: Unsupported API level: 33
	1: undefined
  
	More details for this errors may be available online: https://github.com/ionic-team/native-run/wiki/Android-Errors

Native-run android errors section states it clearly the current supported API level is 31. So as said before downgrading API level helps. (Be sure to remove newer version)

API level 33 related issue: https://github.com/ionic-team/native-run/issues/239

ionic CLI should have some way to detect this error. Maybe I'll do a pull request.

Help for downgrading Android SDK:

  • Open Android Studio
  • File -> Settings menu
  • Find "Android SDK"
  • Check "Show Package Details"
  • Uncheck everything which greater than Android SDK Platform 31
  • Apply
  • ionic cap run android shows Android devices again.

husudosu avatar Jul 15 '22 18:07 husudosu