How to run Ionic app on android-studio with capacitor on Ubuntu?
Asked Answered
V

12

15

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

Variola answered 2/4, 2019 at 18:16 Comment(1)
Have you find anything for this problem yet? I have the same issue.Innocuous
P
27

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

Palladian answered 16/10, 2019 at 14:35 Comment(3)
whereis android-studio returned /snap/bin/android-studio/bin/studio.sh adding this to linuxAndroidStudioPath didn't help, but adding /snap/android-studio/current/android-studio/bin/studio.sh to linuxAndroidStudioPath workedGriffen
What if you are using Typescript instead of JSON for Capacitor configuration file (capacitor.config.ts) ? It doesn't seem to have a property for this setting in the CapacitorConfig interface. CapacitorConfig interface docs can be found hereKirst
whereis android-studio failed for me. I rather had to do whereis studioSumner
H
5

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" 
Headdress answered 13/4, 2021 at 14:34 Comment(0)
C
3

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

Add sudo when running the project sudo npx cap open android

Chromite answered 4/4, 2020 at 10:21 Comment(0)
P
2

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

{
  ...
  "linuxAndroidStudioPath": "/opt/android-studio/bin/studio.sh"
}
Proscribe answered 19/3, 2021 at 0:29 Comment(0)
T
1

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.

Tetchy answered 8/4, 2022 at 12:28 Comment(0)
E
0

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.

Elwell answered 24/3, 2020 at 13:25 Comment(0)
F
0
  • 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

Francinafrancine answered 10/8, 2021 at 11:23 Comment(0)
R
0

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"

Ruffian answered 13/6, 2022 at 6:19 Comment(0)
S
0

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/...

Sumner answered 19/12, 2022 at 9:6 Comment(0)
P
0

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

Pankhurst answered 18/4 at 1:15 Comment(0)
U
0

Added the following line to .bashrc

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

Unamuno answered 18/7 at 2:15 Comment(0)
R
-1

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?

Regale answered 17/6, 2019 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.