speedhacker
speedhacker

Reputation: 151

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

Upvotes: 15

Views: 22897

Answers (12)

danielnaranjo
danielnaranjo

Reputation: 21

Added the following line to .bashrc

export CAPACITOR_ANDROID_STUDIO_PATH=/snap/android-studio/current/bin/studio.sh

Upvotes: 0

Dan Guinn
Dan Guinn

Reputation: 1

Using the following worked for me: (Note: only one android-studio, unlike some of the other answers above)

export CAPACITOR_ANDROID_STUDIO_PATH=/snap/android-studio/current/bin/studio.sh

I added this to .bashrc

Upvotes: 0

Cedric Ipkiss
Cedric Ipkiss

Reputation: 6347

Here's how I solved this: In Ionic 6x, there's no capacitor.config.json. You'd have to set an environment variable of CAPACITOR_ANDROID_STUDIO_PATH globally. Do this by typing

export CAPACITOR_ANDROID_STUDIO_PATH=/path/to/android-studio/studio.sh

Worth noting that my Android Studio is found at /opt/android-studio/bin and not under /snap/...

Upvotes: 0

desw
desw

Reputation: 21

All of the answers here are on point, however I would like to add something small to note.

Its worth noting that Android Studio has different installation locations depending on the distribution you are using and also some installations are command-line based others are offline installations.

Some well known places are:

  • /usr/local
  • /usr/share
  • /opt

Lastly whereas the commands to search for android-studio may work in some instances where the default installation path was not changed. However the command

whereis android-studio

will not return anything in a case where the directory name is not the default i.e

/opt/android-studio-2021.2.1/android-studio/bin/studio.sh"

or

/usr/local/android-studio-2021.2.1/bin/studio.sh"

Upvotes: 0

Sajid Javed
Sajid Javed

Reputation: 507

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

Upvotes: 27

Nitin Yadav
Nitin Yadav

Reputation: 11

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.

Upvotes: 1

pardhu lekkala
pardhu lekkala

Reputation: 1

  • 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

Upvotes: 0

RenRen
RenRen

Reputation: 11407

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" 

Upvotes: 5

Omar Elsehrawy
Omar Elsehrawy

Reputation: 41

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

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

Upvotes: 2

Okan Beydanol
Okan Beydanol

Reputation: 31

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

Add sudo when running the project sudo npx cap open android

Upvotes: 3

NotJohn
NotJohn

Reputation: 98

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.

Upvotes: 0

rtpHarry
rtpHarry

Reputation: 13125

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?

Upvotes: -1

Related Questions