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.
This question is related to
android
environment-variables
java-home
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
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.
source ~/.bash_profile
export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
try with this after add ANDROID_HOME on your Environment Variable, work well on my mac
flutter config --android-sdk ANDROID_HOME
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
If you are setting up the ANDROID_HOME environment 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.
Modified as it's providing answer to the frustration of setting up android_home environment on MacOS.
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.
Based on Abraham Mayowa Oluwasina answer provided above is the correct one. MacOS Catalina, .bash_profile is no longer apple's default shell and it won't persist 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
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
solved my problem on mac 10.14
brew install android-sdk
The above answer is correct. Works really well. There is also quick way to do this.
Type - echo export "ANDROID_HOME=/Users/yourName/Library/Android/sdk" >> ~/.bash_profile
Thats's it.
Close your terminal.
Open it again.
Type - echo $ANDROID_HOME to check if the home is set.
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"
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.
Here are the steps:
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.
MacOS
add this string in file ~/.bashrc or ~/.zshrc
export ANDROID_HOME="/Users/<userlogin>/Library/Android/sdk"
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.
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
Source: Stackoverflow.com