简体   繁体   中英

How can i run ionic-capacitor app on Android-studio or mobile device?

I am trying to run an ionic-capacitor app on android studio or my android phone.

When i run

ionic capacitor run android

It shows:

? Which device would you like to target? (Use arrow keys) and it not showing me any option. i pressed the arrow key still nothing and when i pressed enter it shows:

TypeError: Cannot read property 'value' of undefined

Then i tried

ionic capacitor run android --open After compiling it shows:

[capacitor] [error] Unable to launch Android Studio. Is it installed?

[capacitor] Attempted to open Android Studio at: /usr/local/android-studio/bin/studio.sh

[capacitor] You can configure this with the CAPACITOR_ANDROID_STUDIO_PATH environment variable.

I searched online on how to set CAPACITOR_ANDROID_STUDIO_PATH but i didnt see any solution.

Finally i also tried following the steps in this link in a Stackoverflow answer.

I run adb device to show my device ID

Then i tried

ionic capacitor run android --target 0441925667003082

It showed the following error:

[ERROR] 0441925667003082 is not a valid Target ID.

Use the --list option to list all targets.

I tried to use the --list to list all target but it showing [INFO] No native targets found. despite my android device being connected and showing in the adb devices.

What am i doing wrong in all this steps ?.

How can i run ionic-capacitor on android studio and on my mobile device ?.

I had the same problem, I think it is an error that create a crashe but is not displayed.

This solution worked for me:

ionic capacitor sync

ionic capacitor open android

You need to make sure your environmenent variable ANDROID_SDK_ROOT points to the android sdk location.

Also try re-installing @capacitor/cli and native-run

you have to change your global variable

nano ~/.bashrc  

add end the list

export ANDROID_HOME=$HOME~/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
export ANDROID_SDK_ROOT=~/Android/Sdk/

CTRL + O + Enter

source ~/.bashrc

restart you computer

command is ionic cap open android for Open project in Android Studio.

ionic cap run android for run project via android studio

ionic cap run android --external for liveReload but here need is both of devices connected on same network.

I just had the same problem.

Running this worked for me.

ionic capacitor sync
ionic capacitor run android

the list was perfectly showed after that.

  1. Usually capacitor sometimes not detect device even-though the device is connected. This is due to authentication issue .
  2. To solve this, in Developer options tap on revoke authentications/permissions (verify with your phone).
  3. Turn off USB debugging , turn on USB debugging and Try again.

I had this problem recently. The problem is that I installed AndroidStudio in a random folder.

When you use ionic capacitor run android --open it appears in the /usr/local/ directory. To solve the problem, just move the AndroidStudio installation to this location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM