Set ANDROID_HOME environment variable in mac
Asked Answered
M

19

130

I am new in developing native app using Salesforce SDK. I tried to create android project from command line using forcedroid tool but there is problem in setting environment variable named ANDROID_HOME.

But i don't know how to set this variable.

I am attaching screenshot to describe my problem correctly.

enter image description here

Monge answered 3/2, 2015 at 10:9 Comment(0)
U
155

Open the terminal and type :

export ANDROID_HOME=/Applications/ADT/sdk

Add this to the PATH environment variable

export PATH=$PATH:$ANDROID_HOME/platform-tools

If the terminal doesn't locate the added path(s) from the .zshrc, please run this command

source ~/.zshrc

Hope it works to you!

Unstring answered 3/2, 2015 at 10:13 Comment(5)
When I open a new terminal, echo $ANDROID_HOME shows me empty again.Ankylosis
Check this linkIla
I've done that many times without hope but when I typed source ~/.bash_profile after setting the paths, it solved my issue.Kalb
Why not /.bashrc?Chlamydospore
As this answer answer states if you are on Cataline upward, you have to use .zprofile instead of .bash_profileTransmutation
E
280

To make it permanent on your system and the variable keep working after close the terminal, ou after a restart use:

nano ~/.bash_profile 

Add lines:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator

Reopen terminal and check if it worked:

source ~/.bash_profile
echo $ANDROID_HOME

If you use Oh My Zsh as terminal, you must add these lines to ~/.zshrc instead ~/.bash_profile.

Eureetloir answered 10/11, 2015 at 14:5 Comment(6)
I have to use the source command every time I open a new tab. How can I make it so that ANDROID_HOME is always available?Erythroblast
for MAC OS: Android SDK PATH help: https://mcmap.net/q/101169/-android-studio-sdk-locationMingle
ANDROID_HOME: /Users/<MAC USER NAME>/Library/Android/sdkMingle
Nice answer. add more if your don't know path sdk your can check it #34532563Meyerbeer
Why not write: export ANDROID_HOME=$HOME/Library/Android/sdk ? :)Moritz
@BurkeHolland, You can add those lines in ~/.zshrc instead ~/.bash_profile I guessSchell
U
155

Open the terminal and type :

export ANDROID_HOME=/Applications/ADT/sdk

Add this to the PATH environment variable

export PATH=$PATH:$ANDROID_HOME/platform-tools

If the terminal doesn't locate the added path(s) from the .zshrc, please run this command

source ~/.zshrc

Hope it works to you!

Unstring answered 3/2, 2015 at 10:13 Comment(5)
When I open a new terminal, echo $ANDROID_HOME shows me empty again.Ankylosis
Check this linkIla
I've done that many times without hope but when I typed source ~/.bash_profile after setting the paths, it solved my issue.Kalb
Why not /.bashrc?Chlamydospore
As this answer answer states if you are on Cataline upward, you have to use .zprofile instead of .bash_profileTransmutation
O
55

The above answer is correct. Works really well. There is also quick way to do this.

  1. Open command prompt
  2. Type - echo export "ANDROID_HOME=/Users/yourName/Library/Android/sdk" >> ~/.bash_profile

    Thats's it.

  3. Close your terminal.

  4. Open it again.

  5. Type - echo $ANDROID_HOME to check if the home is set.

Obstacle answered 24/10, 2016 at 11:42 Comment(4)
My home is still not set, it shows me empty even after doing above steps, I am using Sierra Mac.Kizzykjersti
Works great for Mac Catalina echo export "ANDROID_HOME=/Users/appstream/Library/Android/sdk" >> ~/.zshrcBushwhack
I am on Sonoma and can't set ANDROID_HOME, always emptyWitchcraft
@MikeFlynn Did you restart your terminal or call source .zshrc after making your changes?Catacomb
A
36

If you try to run "adb devices" OR any other command and it says something like

zsh: command not found adb

It tells that you are using zsh shell and /.bash_profile won't work as it should. You will have to execute bash_profile everytime with source ~/.bash_profile command when you open terminal, and it isn't permanent.

To fix this run:

nano ~/.zshrc

Terminal image

and then paste following commands at the end of the file

export ANDROID_HOME=/Users/{YourName}/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH

NOTE: You can find Android Home url from Android Studio > Preferences System Settings > Android SDK > Android SDK Location textbox

To save it, hit Ctrl + X, type Y to save and then enter to keep the file name as it is.

Restart the terminal and try your commands again.

Alyss answered 24/8, 2020 at 14:6 Comment(0)
M
26

If you are setting up the ANDROID_HOME environment variable on macOS Catalina, .bash_profile is no longer Apple's default shell, and it won't persist your path variables. Use .zprofile instead and follow the environment setup instructions in react-native documentation or others. .bash_profile will keep creating new file which won't make the path permanent or persist on closing the terminal on your system path.

To create a new path just do this in macOS Big Sur:

  1. sudo touch ~/.zshrc

  2. sudo nano ~/.zshrc

  3. export all the path

  4. crtl + x and save

  5. source ~/.zshrc

  6. Check with echo $PATH

Mizzle answered 30/5, 2020 at 12:42 Comment(0)
B
20

Based on Abraham Mayowa Oluwasina answer provided above is the correct one. MacOS Catalina and later, .bash_profile is no longer apple's default shell and it won't persist in your path variables instead use .zprofile instead.

In root directory,

touch .zprofile
open -e .zprofile

Add the following to file, Android:

export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools

Java:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin

Save and exit

To activate

source ~/. profile
echo $ANDROID_HOME
Berti answered 14/9, 2020 at 5:3 Comment(0)
O
8

The only solution worked for me was @Tiago Gouvêa answer, after adding it android and emulator commands worked fine, but sdkmanager command was not working so I have added one extra line to his solution:

nano ~/.bash_profile

Add lines:

export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
Oleate answered 21/12, 2019 at 13:10 Comment(0)
R
6

As a noob I was struggling a lot with setting up the variable.I was creating copies of .bash_profile files, the text in file was not saving etc ..😳

So I documented the the steps that worked for me. It is simple and foolproof( but little lengthy ) way to do it ✌🏼

Step1. Go to Finder >Go(on top) , click on users, then your user account you will see something like this :

{https://i.stack.imgur.com/8e9qX.png}

Step2. Now hold down ⌘ + ⇧ + . (dot) , this will now display hidden files and folders. It will look something like this:

{https://i.stack.imgur.com/apOoO.png}

PS: If the ⌘ + ⇧ +. does not work, please look up the keyboard shortcut relevant for your Mac Operating system name

Step3.

Scenario A :If .bash_profile already exists

Step3.A.1 :Double click the .bash_profile. It should open up with TextEdit ( or alternatively right click >open with >TextEdit)

Step3.A.2 : Paste the variable text in the .bash_profile file using ⌘ + V

Step3.A.3 :Save the .bash_profile file using ⌘ + S

Scenario B :If .bash_profile does NOT exist This is kind silly way of doing it , but it worked perfectly for noob like me

Step3.B.1 : Download free BBEdit text editor which is pretty light weight. Whats special about this editor is that it lets you save file that starts with ". "

Step3.B.2 : Create a new file

Step3.B.3 : Save the file in your account folder . A warning will pop up , which looks something like this:

{https://i.stack.imgur.com/KLZmL.png}

Click Use"." button. Then the blank .bash_profile file will be saved

Step3.B.4 : Paste the variable text in the .bash_profile file using ⌘ + V

Step3.B.5 :Save the .bash_profile file using ⌘ + S

Step 4: Last and final step is to check if the above steps worked. Open the bash and type echo $ANDROID_HOME

Your ANDROID_HOME variable should be now set.🤜🏻

Roderick answered 15/4, 2019 at 9:9 Comment(0)
C
6

Open Terminal

nano ~/.bash_profile


export ANDROID_HOME=/Users/qss/Library/Android/sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

Control+S to save
Control+X to exit
Y to save changes
Update changes in terminal
source ~/.bash_profile

Validate Path:
echo $PATH

Confirm if all okay:
adb devices
Cundiff answered 23/12, 2019 at 8:42 Comment(0)
O
5
source ~/.bash_profile
export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
Odo answered 27/9, 2017 at 12:11 Comment(1)
Include explanation and proper formatting to your answer.Storybook
S
4

For mac OS monterey 12.0.1

Default terminal is .zsh

Step 1: open terminal then type this command.

nano ~/.zsh    

Step 2: copy below command and past it.

export ANDROID_HOME=/{your sdk path}/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH`

Step3: Press command ^X then press Y then press enter

Stpe4: Close terminal and reopen it Type below command:

echo $ANDROID_HOME

You can find your path. That's it !

Saccharate answered 21/1, 2022 at 12:6 Comment(0)
C
3

MacOS

add this string in file ~/.bashrc or ~/.zshrc

export ANDROID_HOME="/Users/<userlogin>/Library/Android/sdk"
Chronology answered 2/10, 2019 at 18:18 Comment(0)
W
2

Set the path of ANDROID_HOME > You have to open terminal and enter the below cmd.

touch ~/.bash_profile; open ~/.bash_profile

After that paste below paths in base profile file and save it

export ANDROID_HOME=/Users/<username>/Library/Android/sdk 
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
Wharfinger answered 8/5, 2020 at 12:33 Comment(0)
H
1

Firstly, get the Android SDK location in Android Studio : Android Studio -> Preferences -> Appearance & Behaviour -> System Settings -> Android SDK -> Android SDK Location

Then execute the following commands in terminal

export ANDROID_HOME=Paste here your SDK location

export PATH=$PATH:$ANDROID_HOME/bin

It is done.

Horseradish answered 3/4, 2019 at 7:26 Comment(0)
L
1

Here are the steps:

  1. Open Terminal
  2. Type touch .bash_profile and press Enter
  3. Now Type open .bash_profile and again press Enter
  4. A textEdit file will be opened
  5. Now type export ANDROID_HOME="Users/Your_User_Name/Library/Android/sdk"
  6. Then in next line type export PATH="${PATH}:/$ANDROID_HOME/platform-tools:/$ANDROID_HOME/tools:/$ANDROID_HOME/tools/bin"
  7. Now save this .bash_profile file
  8. Close the Terminal

To verify if Path is set successfully open terminal again and type adb if adb version and other details are displayed that means path is set properly.

Lolita answered 15/11, 2019 at 18:51 Comment(0)
N
1

Try with this after add ANDROID_HOME on your Environment Variable, work well on my mac

flutter config --android-sdk ANDROID_HOME

Nassi answered 26/11, 2019 at 4:12 Comment(0)
I
0

Solved my problem on mac 10.14 brew install android-sdk

Imco answered 25/3, 2020 at 21:27 Comment(0)
O
0

If using fish, append these lines to ~/.config/fish/config.fish:

# Setting Android Studio Path for fish
set -x ANDROID_HOME $HOME/Library/Android/sdk
set -x PATH "$ANDROID_HOME/platform-tools" "$PATH"
set -x PATH "$ANDROID_HOME/tools" "$PATH"
set -x PATH "$ANDROID_HOME/tools/bin" "$PATH"
set -x PATH "$ANDROID_HOME/emulator" "$PATH"

After saving the changes, restart fish or type source ~/.config/fish/config.fish.

Owenism answered 29/12, 2023 at 10:56 Comment(0)
R
0

For MacOs ventura and android studio giraffe:

Step 1: For sdk path:

  1. Open Android Studio
  2. Go To Tools tab from top menu
  3. Go SDK manager
  4. In top there is field name Androd SDK Location, you can copy it.

Step 2:

Open ~/.bashrc or ~/.zshrc

Step 3

Paste these commands at the end of the file:

export ANDROID_HOME=/{your sdk path}/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH

Step 4:

Save the file and make sure to close all terminal open for that folder

Step 5:

Open terminal again and type this command to verify Android_Home path:

echo $ANDROID_HOME

if this command not showing anything it means Android_Home not add properly, you need to check and make sure that you save the file properly.

Radiophotograph answered 14/1 at 6:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.