'How to run Ionic app on android-studio with capacitor on Ubuntu?

When I run the ionic capacitor run android command, to launch my application in Android Studio, I get the error saying:

Unable to launch Android Studio." You must configure "linuxAndroidStudioPath" in your capacitor.config.json to point to the location of studio.sh, using JavaScript-escaped paths: example: {   "linuxAndroidStudioPath": "/usr/local/android-studio/bin/studio.sh" }

but I configured the path my capacitor.config.json but the error persists.

enter image description here

Here's my capacitor.config.json file

enter image description here



Solution 1:[1]

First, run whereis android-studio in your terminal. This command will return the path of your android studio.

Mine is /snap/android-studio/current/android-studio/bin/studio.sh. I installed android-studio from the ubuntu software store. Maybe you installed it through a different source and in a different location.

Then add "linuxAndroidStudioPath": "/snap/android-studio/current/android-studio/bin/studio.sh" in capacitor.config.json which is located in the root of your project.

Replace /snap/android-studio/current/android-studio/bin/studio.sh by your path. which is returned to you by whereis android-studio

Solution 2:[2]

"linuxAndroidStudioPath": "/snap/android-studio/current/android-studio/bin/studio.sh" is the path.

Add sudo when running the project sudo npx cap open android

Solution 3:[3]

in my case, android studio location was "/opt/android-studio/bin/studio.sh"

{
  ...
  "linuxAndroidStudioPath": "/opt/android-studio/bin/studio.sh"
}

Solution 4:[4]

I use JetBrains Toolbox and macOS

to open the capacitor project with Android Studio with npx cap open android I had to export the Android Studio path as follow:

export CAPACITOR_ANDROID_STUDIO_PATH="/Users/myuser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7199119/Android Studio.app" 

Solution 5:[5]

Everything looks correct so the likely answer is that you have got the path wrong somehow.

Could you recheck it?

Also, are you running the latest versions of everything?

Solution 6:[6]

I have the same issue and I didn't manage to find out why it can't verify the path for android studio.

In order to use npx cap open android i had to open Android Studio before running the command.

Solution 7:[7]

  • Open your terminal and run gedit .bashrc.

  • Set the environment variable:

    export CAPACITOR_ANDROID_STUDIO_PATH="path of android-studio/bin/studio.sh"
    
  • Save your file with Ctrl+s.

This will read your capacitor directly by running

Ionic cap open android

Solution 8:[8]

Set environment variable--

Step1- Run: nano ~/.bashrc in terminal.

Step2- Add export CAPACITOR_ANDROID_STUDIO_PATH="path of android-studio/bin/studio.sh" in .bashrc file.

Step3- Run npx cap open android in terminal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Basel Issmail
Solution 3 Omar Elsehrawy
Solution 4 RenRen
Solution 5 rtpHarry
Solution 6 NotJohn
Solution 7 Dada
Solution 8 Nitin Yadav