Open AndroidStudio project from command line on OSX

MacosAndroid Studio

Macos Problem Overview


I would like to open an AndroidStudio project from the command line on my Mac. Something like:

~ $ AndroidStudio --path ~/my_android_project

Is this possible in some way?

Macos Solutions


Solution 1 - Macos

Easiest way to use it from command line is to create a shortcut using Android Studio's built in tool: Menu --> Tools --> Create command line launcher.

After that, just call studio myprojectname.

enter image description here

Solution 2 - Macos

how about:

open -a /Applications/Android\ Studio.app /path/to/my_android_project

For Windows user, use the following command:

start "" "C:\Program Files\Android\Android Studio\bin\studio64.exe" "X:\path\to\my_android_project"

Solution 3 - Macos

In your ~/.bash_profile add

alias AndroidStudio="open -a /Applications/Android\ Studio.app"

Then reload your terminal and you can now do

AndroidStudio ~/my_android_project

Solution 4 - Macos

Typing the path to the android studio application binary, followed by a path to an android project directory works for me.

for example:

/Applications/Android\ Studio.app/Contents/MacOS/studio  ~<username>/androidprojects/AndroidAppProjectDirectory

Solution 5 - Macos

Use below command to open your project.

open -a Android\ Studio "Your Project Path"

Solution 6 - Macos

For Mac Catalina and up, paste this line into ~/.zshrc

alias androidstudio="open -a /Applications/Android\ Studio.app"

Save then reload it source ~/.zshrc

Now you able to open specific android project with Android Studio from terminal.

Let's try: androidstudio /path/to/your/project

Solution 7 - Macos

Another way, which relying only on application bundle identifier (regardless application location on disk):

open -b com.google.android.studio /path/to/your/project

Solution 8 - Macos

For Mac users:

If you are using bach:

  • Open Terminal and cd to ~ like this: cd ~
  • Open the .bach_profile file with this command: open .bach_profile
  • Add the following line in the .bach_profile file:
    alias NAMEYOUWANT="/Applications/Android\ Studio.app" for example alias android="/Applications/Android\ Studio.app"
  • Save file and restart Terminal.


If you are using zsh:

  • Open Terminal and cd to ~ like this: cd ~
  • Open the .zshrc file with this command: open .zshrc
  • Add the following line in the .zshrc file:
    alias NAMEYOUWANT="/Applications/Android\ Studio.app" for example alias android="/Applications/Android\ Studio.app"
  • Save file and restart Terminal.

You can now open a project with Android Studio using this command:
open . -a NAMEYOUWANT (with our example it would be: open . -a android)

You can follow these steps to create any alias like opening Xcode, Visual Studio or even shortcut git commands.

Solution 9 - Macos

This is the proper answer. There is some permission related issue. Android studio is not picking PATH.

chmod +x /Applications/Android Studio.app/Contents/bin/printenv

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPKenoView Question on Stackoverflow
Solution 1 - MacosAmir UvalView Answer on Stackoverflow
Solution 2 - MacosGrady PlayerView Answer on Stackoverflow
Solution 3 - MacosShaheen GhiassyView Answer on Stackoverflow
Solution 4 - MacospresterjohnView Answer on Stackoverflow
Solution 5 - MacosKarthik damodaraView Answer on Stackoverflow
Solution 6 - MacosNguyễn Anh TuấnView Answer on Stackoverflow
Solution 7 - MacosVladView Answer on Stackoverflow
Solution 8 - MacosMerouane T.View Answer on Stackoverflow
Solution 9 - MacosDipendra SharmaView Answer on Stackoverflow