Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: CAPACITOR_ANDROID_STUDIO_PATH does not work with JetBrains toolbox managed shell scripts. #5250

Closed
distante opened this issue Nov 18, 2021 · 17 comments

Comments

@distante
Copy link

Bug Report

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 3.3.2
  @capacitor/core: 3.3.2
  @capacitor/android: 3.3.2
  @capacitor/ios: 3.3.2

Installed Dependencies:

  @capacitor/cli: 3.3.2
  @capacitor/android: 3.3.2
  @capacitor/core: 3.3.2
  @capacitor/ios: 3.3.2

Platform(s)

MacOs

Current Behavior

JetBrains ToolBox has integrated shell scripts that point to the latest Android studio version installed. (see here). This is done because each release incorporates the build ID on the path, so a hard coded path will always break after a version update.

Setting the path of the generated studio.sh script into CAPACITOR_ANDROID_STUDIO_PATH fails with:

[error] Unable to launch Android Studio. Is it installed?
        Attempted to open Android Studio at: /usr/local/bin/studio.sh
        You can configure this with the CAPACITOR_ANDROID_STUDIO_PATH environment variable.

Expected Behavior

We could be able to give this script to open capacitor projects.

Code Reproduction

--

Other Technical Details

The generated script looks like this:

#!/bin/bash
#Generated by JetBrains Toolbox 1.22.10740 at 2021-11-18T10:21:56.087264

declare -a ideargs=()
declare -- wait=""

for o in "$@"; do
  if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
    wait="-W"
    o="--wait"
  fi
  if [[ "$o" =~ " " ]]; then
    ideargs+=("\"$o\"")
  else
    ideargs+=("$o")
  fi
done

open -na "/Users/my-user/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7784292/Android Studio.app/Contents/MacOS/studio" $wait --args "${ideargs[@]}"%      
@tomavic
Copy link

tomavic commented Dec 13, 2021

Same problem here with Mac M1. I have to open Android studio manually.

@saschpe
Copy link
Contributor

saschpe commented Jan 6, 2022

You can put this in your .zshrc or .bashrc as a workaround:

androidStudioToolboxBase="${HOME}/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0"
androidStudioToolboxVersion=$(ls ${androidStudioToolboxBase})
export CAPACITOR_ANDROID_STUDIO_PATH=${androidStudioToolboxBase}/${androidStudioToolboxVersion}/Android\ Studio.app/

It would be better if that location is checked as well by default on Apple hardware.

@butaminas
Copy link

You can put this in your .zshrc or .bashrc as a workaround:

androidStudioToolboxBase="${HOME}/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0"
androidStudioToolboxVersion=$(ls ${androidStudioToolboxBase})
export CAPACITOR_ANDROID_STUDIO_PATH=${androidStudioToolboxBase}/${androidStudioToolboxVersion}/Android\ Studio.app/

It would be better if that location is checked as well by default on Apple hardware.

I use MacOS and I had to remove quotes from the first line for it to work. Thanks for sharing!

@wstidolph
Copy link

Different form of "not work" - I get Finder windows?

I've got my JetBrains products installed via Toolbox. If I manually open Studio and then open the project's android directory my project runs. But of course if I just use npx cap open android then I get Attempted to open Android Studio at: /Applications/Android Studio.app and nothing happens.

I can't easily set the androidStudioToolboxVersion as suggested by @butaminas because Toolbox has installed multiple versions in the androidStudioToolboxBase directory.

So, I set up Toolbox to generate scripts and set the env var in my .zshrc: to point at the Toolbox's script:

export CAPACITOR_ANDROID_STUDIO_PATH="/Users/waynestidolph/Library/Application Support/JetBrains/Toolbox/scripts/studio"

Now, from a terminal command line I can simply execute $CAPACITOR_ANDROID_STUDIO_PATH and Studio launches nicely. But, when using npx cap open android from my project's root rather than getting Studio, I get one or two Finder windows launched - the Finder windows are on my project's android directory and on my project's root directory.

I'm a Mac-newbie (M1 Mac Mini, macOS Monterey 12.4), so maybe I'm missing something obvious ...

If I manually open Studio and then open the project's android directory my project runs.

@Dante1349
Copy link
Contributor

If you go to the toolbox app and look into the settings, you find an option "Generate shell scripts", you can define a path or use the default path. The toolbox app will generate a binary to open android studio there, then simply use the path to the studio binary as CAPACITOR_ANDROID_STUDIO_PATH. I've been doing this on linux and mac.

@gabrielmaldi
Copy link

If you go to the toolbox app and look into the settings, you find an option "Generate shell scripts", you can define a path or use the default path. The toolbox app will generate a binary to open android studio there, then simply use the path to the studio binary as CAPACITOR_ANDROID_STUDIO_PATH. I've been doing this on linux and mac.

Thank you. But it seems cap open android is not working for me with this setup even though everything seems to be correctly in place:

Screenshot 2022-11-02 at 12 07 34

@CTOlet
Copy link

CTOlet commented Dec 14, 2022

I have this issue too

@Dante1349
Copy link
Contributor

@gabrielmaldi try to set the CAPACITOR_ANDROID_STUDIO_PATH variable to the full path to the binary, this should work

@gabrielmaldi
Copy link

Same error using export CAPACITOR_ANDROID_STUDIO_PATH=/Users/gabrielmaldi/.local/bin/studio:

Screenshot 2022-12-19 at 19 14 27

@rhiskey
Copy link

rhiskey commented Mar 18, 2023

In Windows it wont start...

ERROR: The system was unable to find the specified registry key or value.
 App • ⚠️  Cannot determine path to IDE executable
 Please set quasar.config.js > bin > windowsAndroidStudio with the escaped path to your studio64.exe
 Example: 'C:\\Program Files\\Android\\Android Studio\\bin\\studio64.exe'

@ptmkenny
Copy link

Jetbrains Toolbox now seems to helpfully place files here on macOS:

$HOME/Applications/JetBrains\ Toolbox/Android\ Studio.app/Contents/MacOS/jetbrains-toolbox-launcher

So there's no need to mess with identifying the version and such anymore.

If it's as simple as running this script, I definitely think that capacitor should automatically check this path as well.

@VitorHFLopes
Copy link

I'm using this in .zshrc

export CAPACITOR_ANDROID_STUDIO_PATH="$HOME/Applications/Android Studio.app/Contents/MacOS/studio"

Working on Mac M2!
Hope it helps! 🙏🏼

@alikaramniya
Copy link

Hi
I'm solve this problem and use .zshrc

first use belog command

whereis  studio.sh

then copy path for me /opt/android-studio/bin/studio.sh

then paste below command in .zshrc file

export CAPACITOR_ANDROID_STUDIO_PATH="/opt/android-studio/bin/studio.sh"

then source .zshrc and finish :)

@parollon
Copy link

Different form of "not work" - I get Finder windows?

I've got my JetBrains products installed via Toolbox. If I manually open Studio and then open the project's android directory my project runs. But of course if I just use npx cap open android then I get Attempted to open Android Studio at: /Applications/Android Studio.app and nothing happens.

I can't easily set the androidStudioToolboxVersion as suggested by @butaminas because Toolbox has installed multiple versions in the androidStudioToolboxBase directory.

So, I set up Toolbox to generate scripts and set the env var in my .zshrc: to point at the Toolbox's script:

export CAPACITOR_ANDROID_STUDIO_PATH="/Users/waynestidolph/Library/Application Support/JetBrains/Toolbox/scripts/studio"

Now, from a terminal command line I can simply execute $CAPACITOR_ANDROID_STUDIO_PATH and Studio launches nicely. But, when using npx cap open android from my project's root rather than getting Studio, I get one or two Finder windows launched - the Finder windows are on my project's android directory and on my project's root directory.

I'm a Mac-newbie (M1 Mac Mini, macOS Monterey 12.4), so maybe I'm missing something obvious ...

If I manually open Studio and then open the project's android directory my project runs.

I works!! export CAPACITOR_ANDROID_STUDIO_PATH="$HOME/.local/share/JetBrains/Toolbox/scripts/studio

@parollon
Copy link

Different form of "not work" - I get Finder windows?

I've got my JetBrains products installed via Toolbox. If I manually open Studio and then open the project's android directory my project runs. But of course if I just use npx cap open android then I get Attempted to open Android Studio at: /Applications/Android Studio.app and nothing happens.

I can't easily set the androidStudioToolboxVersion as suggested by @butaminas because Toolbox has installed multiple versions in the androidStudioToolboxBase directory.

So, I set up Toolbox to generate scripts and set the env var in my .zshrc: to point at the Toolbox's script:

export CAPACITOR_ANDROID_STUDIO_PATH="/Users/waynestidolph/Library/Application Support/JetBrains/Toolbox/scripts/studio"

Now, from a terminal command line I can simply execute $CAPACITOR_ANDROID_STUDIO_PATH and Studio launches nicely. But, when using npx cap open android from my project's root rather than getting Studio, I get one or two Finder windows launched - the Finder windows are on my project's android directory and on my project's root directory.

I'm a Mac-newbie (M1 Mac Mini, macOS Monterey 12.4), so maybe I'm missing something obvious ...

If I manually open Studio and then open the project's android directory my project runs.

It works!! export CAPACITOR_ANDROID_STUDIO_PATH="$HOME/.local/share/JetBrains/Toolbox/scripts/studio

@ZaLiTHkA
Copy link

I just recently moved my development environment from Windows to macOS, and found myself running into this same issue...

I have JetBrains Toolbox installed and running with all default options, nothing fancy there. checking the Android Studio settings inside Toolbox, I see the following:

image

..so I added the following line to my ~/.zshrc:

export CAPACITOR_ANDROID_STUDIO_PATH="$HOME/Applications/Android Studio.app"

..and now nx run <my_app>:open:android works perfectly. hopefully this helps a bit.


with that said, I feel like this would be resolved by simply making this switch statement condition in determineAndroidStudioPath check both /Applications/Android Studio.app and $HOME/Applications/Android Studio.app... unless there's any reason to not do so?

@jcesarmobile
Copy link
Member

closing since there has been several workarounds about how to get the Android Studio path to configure the CAPACITOR_ANDROID_STUDIO_PATH when it's not installed in the default path.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests