Open AndroidStudio project from command line on OSX
Asked Answered
L

10

106

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?

Liberalism answered 12/2, 2016 at 13:14 Comment(0)
S
204

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

Sordino answered 15/1, 2018 at 15:33 Comment(9)
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).Noami
This one is the simplest and best of all.Phio
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.Birecree
This should be the accepted answer. This is the way.Malindamalinde
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 .Poignant
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'Ogdoad
@Ogdoad in which version are you trying? I still see the option in studio 4.2.1, and in intellij idea 2021.2.1 ultimateSordino
@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).Ogdoad
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.Chrystalchryste
P
153

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"

Procurance answered 27/4, 2016 at 1:43 Comment(5)
Works great. I added the alias: alias androidstudio="open -a /Applications/Android\ Studio.app" so I can do e.g. androidstudio ~/my_android_project. ThanksLiberalism
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! ;-)Inigo
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".Jonell
@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.Procurance
even this is enough open -a /Applications/Android\ Studio.appHrutkay
E
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
Encase answered 11/10, 2016 at 5:45 Comment(0)
C
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

Campestral answered 28/6, 2021 at 2:14 Comment(1)
Its Working.Thanks.Phio
K
5

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
Kami answered 27/4, 2016 at 1:39 Comment(1)
This is the proper solution if you want to preserve environment variables from your shell session.Lota
A
5

Use below command to open your project.

open -a Android\ Studio "Your Project Path"

Adulteress answered 7/8, 2017 at 6:53 Comment(0)
I
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
Interweave answered 16/3, 2020 at 7:31 Comment(1)
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'Ogdoad
A
3

For mac users

Simply run in project directory

studio .

If you receive studio command not found

Then you need to add the following path to PATH variable as below

If you're a zsh user run this in terminal

open ~/.zshrc

Add this to the file

export PATH=$PATH:"/Applications/Android Studio.app/Contents/MacOS"

save and close file

Run this to apply previous changes in current terminal

source ~/.zshrc

Now try to run studio . again in project directory

Hope this help someone

Aquarist answered 23/1 at 14:40 Comment(0)
C
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.

Cavin answered 16/11, 2020 at 16:42 Comment(0)
I
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
Inviolable answered 28/1, 2022 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.