0

I get this error:

Failed to find 'ANDROID_HOME' environment variable. Try setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.

This happens because I have on .bashrc the $ANDROID_HOME and $PATH set up, but when I run sudo ionic cordova build --release android doesn't detect it to me. What should I do?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
M. Mariscal
  • 1,226
  • 3
  • 17
  • 46
  • export PATH=/platform-tools:/tools:$PATH add tools also like above – TheParam Feb 14 '19 at 13:52
  • When using `sudo`, the environment variables change. Try `sudo env`, does it shows the `ANDROID_HOME` ? – Derlin Feb 14 '19 at 13:53
  • if you're using Mac maybe this can help you https://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x – Tung Duong Feb 14 '19 at 14:04
  • Finally i've changed the owner (Don't know why i dont have permissions all the time, doing some stuff on Ionic...) I have to change the permissions all time... and it works perfectly! finally was with sudo it doesn't work... – M. Mariscal Feb 14 '19 at 15:59

1 Answers1

2

My guess is that your sudo is not configured to keep the PATH (see env_keep in sudoers). So when running a command using sudo, there is not ANDROID_HOME defined anymore.

A quick way to find out is to run sudo env | grep -i android.

To solve the problem, many ways:

  1. change the sudo setting so your PATH environment variable is left unchanged (using env_keep in settings, google is your friend);
  2. define the ANDROID_HOME variable in /root/.profile or /etc/profile, etc.
  3. etc.
Derlin
  • 9,572
  • 2
  • 32
  • 53