Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic android build Error - Failed to find 'ANDROID_HOME' environment variable

I am trying to build android for ionic in linux but its showing me an error like this

     [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.]
      ERROR building one of the platforms: Error: /home/kumar/myapp/platforms/android/cordova/build: Command failed with exit code 2
      You may not have the required environment or OS to build this project
      Error: /home/kumar/myapp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)

and i've added this in my bashrc file

export ANT_HOME="/usr/bin/ant"
export PATH="$PATH:$ANT_HOME/bin"
export HOME="/home/kumar"
export ANDROID_HOME="$HOME/android-sdk-linux/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-sdk-linux/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

I'm thinking i've given the path but i dont know why its showing me this error .. Please help....

like image 407
Kumar Elubandi Avatar asked Sep 14 '15 04:09

Kumar Elubandi


2 Answers

Android Home should be the root folder of SDK.

export ANDROID_HOME="$HOME/android-sdk-linux"

EDIT: Open terminal and type these commands. (yes, on a ternimal , not in bashrc file)

export ANDROID_HOME=~/android-sdk-macosx
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools    

and then in the same terminal just type android. If configured you would be able to use build commands from this terminal. (it's a temporary solution)

like image 92
Karan Kumar Avatar answered Sep 23 '22 23:09

Karan Kumar


For OSX

  • into ~/.bash_profile add:

    export ANDROID_HOME="/path/to/android-sdk-macosx"
    export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
    

    and then execute it in terminal to take effect immediately;

  • into /etc/sudoers add: (you can use console: sudo visudo)

    Defaults        env_keep += "ANDROID_HOME"
    

    since the building process has to start with sudo and Node's process.env get the respective variables.

like image 14
Denis S Kryukov Avatar answered Sep 23 '22 23:09

Denis S Kryukov