1

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!!

3
  • have you installed the android sdk tools and platform tools using the SDK manager? Commented Mar 25, 2015 at 0:01
  • Yes, I did! I have version 19. Does it matter? Commented Mar 25, 2015 at 10:47
  • 19 is perfect, it's the one used by default by cordova. In your profile folder, you should have a .cordova folder, and somewhere in there you should find a script named check_reqs script (something like .cordova/lib/android/cordova/3.6.4/bin/check_reqs). If you run it, you may get a more acurate error message. Commented Mar 25, 2015 at 14:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It worked! Finally I realized that I had to give permisson to assets folder and it worked without sudo. Thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.