I am new to mobile automation.
I am setting up appium on my MAC.
When I am running appium-doctor in a new terminal, I am getting error for ANDROID_HOME
info AppiumDoctor ### Diagnostic starting ###
WARN AppiumDoctor ANDROID_HOME is NOT set!
WARN AppiumDoctor JAVA_HOME is NOT set!
WARN AppiumDoctor adb could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor android could not be found because ANDROID_HOME is NOT set!
WARN AppiumDoctor emulator could not be found because ANDROID_HOME is NOT set!
info AppiumDoctor ### Diagnostic completed, 5 fixes needed. ###
info AppiumDoctor
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Manually configure ANDROID_HOME.
WARN AppiumDoctor - Manually configure JAVA_HOME.
WARN AppiumDoctor - Manually configure ANDROID_HOME and run appium-doctor again.
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye, run appium-doctor again when the all the manual fixes have been applied!
info AppiumDoctor
When I am opening a new terminal and giving command : source ~/.bash_profile , everything is working fine.
Is there any solution for this, where I don’t have to give this command all the time?
I have downloaded the appium desktop version as well. When I run Appium Doctor from there, I get the error for “ANDROID_HOME” not set.
Look at the manual page for Bash. On OS X systems, the .bash_profile file is not read by Bash because none of the shells launched on the system are login shells. .bash_profile is practically never read on OS X.
Try adding the line “echo hello from bashrc!” at the bottom of your .bashrc and then starting a new terminal. If you see the “hello” when you start a new shell, then this means .bashrc is being read by Bash. This would at least tell you whether or not the file is being read.
Also, I must have screwed up my understanding of Bash on OS X. It turns out that Bash can and does read a startup profile file on OS X. I have some settings stored inside a file called .profile.
If you have to use sudo, that means the file’s owner and permissions might not be set correctly. Use ls -a to ensure that your .bashrc file is owned by the user of the home directory the .bashrc file sits in, and that the file has at least read-write permissions for this user (so that you can edit it without sudo, and so that bash can read it at startup).
If the .bashrc file isn’t being read, there might be something blocking the shell from reading it at startup. Try adding a debugging print statement at the top of the .bashrc file, like echo hello from the beginning. See if this shows up.
Use chown to change the file’s owner to the user of the home directory those files are sitting in. You also want to change the group to the user’s group as well. You’ll need sudo to change it this time.
groups – first group listed should be the user’s main group.
I recommend spending some time learning how to use a Unix system instead of immediately trying to set up Appium. You’ll find a lot of tutorials online that pertain to Linux, but many of the concepts presented will equally apply to OS X.
Another good thing to check is to make sure you are running Bash. Try echo $SHELL to make sure that the shell is Bash. On my systems, this prints “/bin/bash”.
Also, what does your .bash_profile file say? (I’m redacting my previous statement about Bash not reading .bash_profile). Try adding some echo commands inside that file to check if Bash actually is reading from that file.
If you type man bash, you’ll see the manual for Bash. You can navigate up and down the using the ‘j’ and ‘k’ keys on your keyboard. You can close the manual by pressing ‘q’.
/bin/sh is a historical version of a shell. Bash is similar to sh, but it has some additional features. If you see /bin/sh, that means you’re running this historical version of sh rather than Bash (or you might be running Bash, but it’s behaving like sh, but this is besides the point - you’re effectively running with an sh-like environment). /bin/sh does not read .bash_profile nor does it read .bashrc, so the variables you want set are never actually set.
One workaround is to rename .bash_profile to .profile. .profile is a special file that will be read by both /bin/sh and bash, so in either case you’ll have somewhere that gets read. You’d have to move the contents in .bashrc into .profile, however.
Another solution is to change your default shell from /bin/sh to bash. I’m not too clear on how it’s done on OS X (Linux systems store this information in /etc/passwd), but you can change the default shell in the terminal application by looking under its Preferences; the default shell should be settable under the General tab.
As another solution, I have a special line in my .profile that looks like the following:
if [ -f "$HOME/.bashrc" ]; then
source "$HOME/.bashrc"
fi
With this, I ensure that my settings in .bashrc will always be read whether I login or when I launch a new shell. I actually have most of my environment variables set inside my .profile file, though, since this file is read only once, and the variables are inherited throughout all my processes.