104

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?

PKeno
  • 2,694
  • 7
  • 20
  • 37

9 Answers9

195

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

Amir Uval
  • 14,425
  • 4
  • 50
  • 74
  • 19
    I don't know when this was added, but it's by far the best solution for the problem. It should be set as the accepted answer (even though the other answers are still correct). – noamtm Feb 14 '18 at 14:47
  • 1
    This one is the simplest and best of all. – Tunvir Rahman Tusher Apr 13 '20 at 15:08
  • This also works when a project requires "importing" and it's cross-platform (I assume). Previously I was using "open -a" which worked somewhat but did not import our old project correctly. It was also Mac-only. – Form Oct 09 '20 at 18:20
  • 1
    This should be the accepted answer. This is the way. – Rishav Feb 09 '21 at 11:48
  • 2
    In addition to proposed solution, when applied you can also run android studio in folder where you got your project already similarly like with code like so: vscode `code .` android studio `studio .` – Msmkt Jul 20 '21 at 10:18
  • 1
    This method no longer works, Android Studio (JetBrains?) moved it. I did the same thing by making an alias in my bash/zsh profile: `alias studio='open -b com.google.android.studio'` – jj. Dec 07 '21 at 15:10
  • @jj. in which version are you trying? I still see the option in studio 4.2.1, and in intellij idea 2021.2.1 ultimate – Amir Uval Dec 08 '21 at 13:05
  • @AmirUval studio "2020.3.1 Patch 3" on a Mac - the option in the menu is there, but it displays a dialog: "Launcher script creation is now managed in Toolbox App Settings. See Toolbox App announcement for more details". Coincidentally the Toolbox App doesn't have it anymore (that I can tell). – jj. Dec 08 '21 at 17:31
  • Works on 2020.3.1 Patch 4. @jj maybe try again? Also, for anyone with an issue where Android Studio opens but the file doesn't display, you may need to go in and select "Create Command-line Launcher" again, and tell it to overwrite the current file. – Kevin Worth Jan 10 '22 at 19:19
152

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"

JeffUK
  • 4,107
  • 2
  • 20
  • 34
Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • 25
    Works great. I added the alias: `alias androidstudio="open -a /Applications/Android\ Studio.app"` so I can do e.g. `androidstudio ~/my_android_project`. Thanks – PKeno Apr 27 '16 at 14:25
  • 12
    And I added the alias `alias android='open -a /Applications/Android\ Studio.app .'` so that I can just type `android` in any Android Studio project's directory and have it open. It's the little things! ;-) – mbm29414 Jan 25 '17 at 14:05
  • 1
    On Windows you don't even need `start ""`, it's enough to do `"C:\Program Files\Android\Android Studio\bin\studio64.exe" "X:\path\to\my_android_project"`. – Donald Duck Dec 06 '21 at 10:25
  • @DonaldDuck I didn't add the windows part, I don't know the differences... on Mac you can execute the executable directly and give it a file as an argument, and it might work... but it isn't exactly the same as having the finder open the application with a document, idk if windows is the same or different. – Grady Player Dec 06 '21 at 14:09
  • even this is enough `open -a /Applications/Android\ Studio.app` – Pavithra Purushothaman Jun 16 '22 at 11:01
21

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
Shaheen Ghiassy
  • 7,397
  • 3
  • 40
  • 40
10

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

alias asd="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: asd /path/to/your/project

Nguyễn Anh Tuấn
  • 1,023
  • 1
  • 12
  • 19
5

Use below command to open your project.

open -a Android\ Studio "Your Project Path"

Akshay
  • 2,506
  • 4
  • 34
  • 55
Karthik damodara
  • 1,805
  • 19
  • 17
4

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
3

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

open -b com.google.android.studio /path/to/your/project
Vlad
  • 6,402
  • 1
  • 60
  • 74
  • `Tools > Create command line launcher` no longer works. This is the only command that works for me. You can make your own alias to open it in your bash/zsh profile: `alias studio='open -b com.google.android.studio'` – jj. Dec 07 '21 at 15:08
2

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.

Merouane T.
  • 746
  • 1
  • 10
  • 14
0

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
Dipendra Sharma
  • 2,404
  • 2
  • 18
  • 35