Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually

Im using Cordova in Linux mint 17

I installed android sdk , cordova , android studio , nodejs 4

problem is here when i wanna build app in codova and run this on terminal :

sudo cordova build android

it shows

Running command: /home/tnt/hello12/platforms/android/cordova/build 
[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/tnt/hello12/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/tnt/hello12/platforms/android/cordova/build: Command failed with exit code 2

I put this code

 export HOME="/home/tnt"
    export ANDROID_HOME="$HOME/android/sdk/tools"
    export ANDROID_PLATFORM_TOOLS="$HOME/android/sdk/platform-tools"
    export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
    export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
    export ANT_HOME="/usr/share/ant"
    export PATH="$ANT_HOME/bin:$PATH"
    export ANDROID_HOME="/home/tnt/android/sdk/tools"

on my

/home/tnt/.bash_profile  
/home/tnt/.bashrc
/home/tnt/.profile  
/root/.bash_profile  
/root/.bashrc
/root/.profile 

but it wont works

like image 857
Milad JVR Avatar asked Jan 03 '16 15:01

Milad JVR


People also ask

What is Android_home variable?

Android SDK environment variables. ANDROID_HOME. Sets the path to the SDK installation directory. Once set, the value does not typically change, and can be shared by multiple users on the same machine. ANDROID_SDK_ROOT , which also points to the SDK installation directory, is deprecated.

How do you verify Android_home has been added?

properties, first make sure that the file is there in your project folder/android. If the file is there open it and make sure that the sdk. dir is pointing to your android SDK directory. Secondly, make sure that the ANDROID_HOME is there in the system variables and is also pointing to your android SDK directory.


2 Answers

I don't think its necessary to add everything into path.Just add the JAVA_HOME , ANDROID_HOME and ANT_HOME to path and point out the corresponding bin directory as:

For android studio

add this into your ~/.bashrc file:

1.export ANDROID_HOME=/path/to/android/studio
2.export PATH=$PATH:$ANDROID_HOME/bin

you can do the same for Ant.

For java jdk

add this into your /etc/profile file:

1.JAVA_HOME=/path/to/jdk
2.JRE_HOME=$JAVA_HOME/jre
3.PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
4.export JAVA_HOME
5.export JRE_HOME
6.export PATH

Now in your terminal, type echo $PATH and make sure all the environment variables are added to the PATH!

like image 148
ishwor kafley Avatar answered Oct 16 '22 03:10

ishwor kafley


You should edit /etc/sudoers with

sudo visudo

At the end of the file enter:

Defaults    env_keep +="ANDROID_HOME"
like image 7
Igor Ilić Avatar answered Oct 16 '22 03:10

Igor Ilić