0

I am trying to run a hybrid app on my android phone using ionic using the following command:

sudo ionic run android

However I keep receiving this error :

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

I have already added platform tools & tools to PATH updated ANDROID_HOME to point to my sdk root.

The ANDROID_HOME environment variable shows up when I run env and the PATH has the tools and platform tools too. Additionally I can execute android too. It launches the SDK Manager as expected.

Details:

ANDROID_HOME: /home/user/Android/Sdk $PATH: /home/user/Android/Sdk/tools:/home/user/Android/Sdk/platform-tools

Please help! This is driving me up the wall!

Flame of udun
  • 2,136
  • 7
  • 35
  • 79
  • which OS are you using? Also could you post those path and android_home variables value? – Gandhi Jun 07 '16 at 06:04
  • 1
    Did you add the android platform also in `sudo`? I think it has permission problems going on. It is greatly discouraged to use `sudo` when running with cordova/ionic. – dariru Jun 07 '16 at 06:04
  • @Gandhi I am using Ubuntu 16.04. @Dar I may have added the android platform in sudo. Could it be the problem? When I looked up the `env` variables after `sudo su`, `ANDROID_HOME` didn't show up. `android` wasn't working either. – Flame of udun Jun 07 '16 at 06:09
  • @VineetKaushik can you try removing the android platform and then adding it back without sudo? `sudo ionic platform remove android`, then `ionic platform add android` then `ionic build android --verbose` to see if it builds okay – dariru Jun 07 '16 at 06:14
  • @VineetKaushik Try executing the following commands: export PATH=$PATH:/opt/android-sdk/platform-tools export PATH=$PATH:/opt/android-sdk/tools export ANDROID_HOME=/opt/android-sdk Suggest to have a look at this link - https://www.thepolyglotdeveloper.com/2014/09/install-android-cordova-ionic-framework-ubuntu/ – Gandhi Jun 07 '16 at 06:16
  • @Dar it says permission denied `/usr/local/lib/node_modules/cordova/node_modules/configstore/index.js:53 throw err;` – Flame of udun Jun 07 '16 at 06:16
  • @Gandhi yep I've seen that tutorial already. – Flame of udun Jun 07 '16 at 06:23
  • @Dar it turns out it was a problem with `sudo` after all. I found a solution to it. – Flame of udun Jun 07 '16 at 06:25
  • 1
    @VineetKaushik Good to hear. If you need a workaround without using `sudo` at all: http://stackoverflow.com/a/37535726/2036808 – dariru Jun 07 '16 at 06:27
  • Check this link : http://stackoverflow.com/a/35960516/6449750 – Hardik Vaghani Jun 22 '16 at 11:03

1 Answers1

1

Credit for this goes to @heemayl on AskUbuntu.

https://askubuntu.com/a/783805/247116

sudo sanitizes the environment and by default only keeps certain environment variables available with modifying the values of some (e.g. PATH).

You can pass the variable ANDROID_HOME manually:

sudo ANDROID_HOME="/actual/path" ionic run android

Or preserve the current environment:

sudo -E ionic run android

Community
  • 1
  • 1
Flame of udun
  • 2,136
  • 7
  • 35
  • 79