Verònica Jandrew
Verònica Jandrew

Reputation: 462

Does not recognize android command in path

I'm triying to build my first cordova project, when I'm inside the project folder i tip: sudo cordova build android and I get the following error:

[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/veritopsecret/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project

when I do echo $PATH I get:

veritopsecret@veritopsecret-SATELLITE-PRO-C50-A-1HQ:~/hello$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/veritopsecret/Escriptori/android-sdk-linux/tools:/home/veritopsecret/Escriptori/android-sdk-linux/platform-tools

I have also modified .profile file, but it stills say that it hasn't android command in the PATH. However, if I just write android, it opens the android sdk manager. Help please!!

Upvotes: 1

Views: 1175

Answers (1)

QuickFix
QuickFix

Reputation: 11721

As I re-read your question, I see you run sudo cordova build android

I think the issue you have is that you define ANDROID_HOME and add the android tools to the path of your user but then you use sudo to run the build.

sudo runs with elevated privileges using a user which is not your user profile that you are logged with, so the path and ANDROID_HOME are not set. (maybe try sudo echo $PATH to be sure of that).

So if you really wanted to use sudo to build, you would need either to define the vars for the sudo user or use instead sudo -E (see this page for more details : https://wiki.archlinux.org/index.php/Sudo#Environment_variables)

But actually, you should be using sudo only when installing cordova, not when using the CLI.

So, just run cordova build android and everything should be fine.

Upvotes: 1

Related Questions