ANDROID_HOME issues on Appium-Mac

Hi,

I am new to mobile automation.
I am setting up appium on my MAC.

  1. When I am running appium-doctor in a new terminal, I am getting error for ANDROID_HOME
    info AppiumDoctor ### Diagnostic starting ###
    WARN AppiumDoctor :heavy_multiplication_x: ANDROID_HOME is NOT set!
    WARN AppiumDoctor :heavy_multiplication_x: JAVA_HOME is NOT set!
    WARN AppiumDoctor :heavy_multiplication_x: adb could not be found because ANDROID_HOME is NOT set!
    WARN AppiumDoctor :heavy_multiplication_x: android could not be found because ANDROID_HOME is NOT set!
    WARN AppiumDoctor :heavy_multiplication_x: 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

  2. 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?

  3. 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.

Thanks!!

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.

What you want to look at instead is .bashrc.

1 Like

Thanks for the response.
Should I setup the ANDROID_HOME and JAVA_HOME under /=.bashrc?

I copy pasted the path from bash_profile file to .bashrc but still getting same issue

Hmm… did you kill and restart bash?

I tried it. Still same issue. This time appium-doctor is running without running the source command

This is my .bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

export ANDROID_HOME=/Users/mguhe/Documents/Android/android-sdk-macosx
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platforms
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK=$ANDROID_HOME

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.

Its not showing it
Also I have to do sudo for editing the file all the time

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.

-rw-r–r-- 1 root wheel 274 Mar 2 16:46 .bash_profile
-rw-r–r-- 1 root wheel 312 Mar 7 16:52 .bashrc

This is what I am getting

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.

How do I find out : user of the home directory those files are sitting in?
same for group?

echo $HOME

whoami

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.

I will start learning about it right away. Thanks for your help. I need to do this setup asap and I really appreciate your help.

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.

echo $SHELL
/bin/sh
Checking for bash_profile

I added echo inside .bash_profile and in new terminal, it didn’t show on start.

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.