Set ANDROID_HOME environment variable in mac

AndroidEnvironment VariablesJava Home

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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=/YOUR_PATH_TO/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

Solution 2 - Android

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!

Solution 3 - Android

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.

Solution 4 - Android

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

Solution 5 - Android

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.

Solution 6 - Android

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 in file,

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

Save and exit

To activate

source ~/. zprofile

echo $ANDROID_HOME

Solution 7 - Android

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.卵

Solution 8 - Android

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

Solution 9 - Android

source ~/.bash_profile
export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH

Solution 10 - Android

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

Solution 11 - Android

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 !

Solution 12 - Android

MacOS

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

export ANDROID_HOME="/Users/<userlogin>/Library/Android/sdk"

Solution 13 - Android

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"

Solution 14 - Android

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.

Solution 15 - Android

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.

Solution 16 - Android

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

flutter config --android-sdk ANDROID_HOME

Solution 17 - Android

solved my problem on mac 10.14 brew install android-sdk

Solution 18 - Android

If some one is still finding difficulties, i have made a video on this

https://www.youtube.com/watch?v=tbLAHKhjjI4

Because the new version of Apple does not support bash shell so i have explained in details how do we set variables in 2020.

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
Questiondharmendra vaishnavView Question on Stackoverflow
Solution 1 - AndroidTiago GouvêaView Answer on Stackoverflow
Solution 2 - AndroidSkizo-ozᴉʞSView Answer on Stackoverflow
Solution 3 - AndroidSantosh PillaiView Answer on Stackoverflow
Solution 4 - AndroidAbraham Mayowa OluwasinaView Answer on Stackoverflow
Solution 5 - AndroidSunny DrallView Answer on Stackoverflow
Solution 6 - AndroidPSKView Answer on Stackoverflow
Solution 7 - AndroidzennniView Answer on Stackoverflow
Solution 8 - AndroidKhaled JamalView Answer on Stackoverflow
Solution 9 - AndroidfsvssvView Answer on Stackoverflow
Solution 10 - AndroidKeshav GeraView Answer on Stackoverflow
Solution 11 - AndroidVrajeshView Answer on Stackoverflow
Solution 12 - AndroidMaksim AlyabyshevView Answer on Stackoverflow
Solution 13 - AndroidBheem SinghView Answer on Stackoverflow
Solution 14 - AndroidApurva AggarwalView Answer on Stackoverflow
Solution 15 - AndroidAbhishekView Answer on Stackoverflow
Solution 16 - AndroidDeni RohimatView Answer on Stackoverflow
Solution 17 - AndroidHeshamSalamaView Answer on Stackoverflow
Solution 18 - AndroidKashan HaiderView Answer on Stackoverflow