Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't build cordova project, PATH error

while running cordova build from my app directory i get following 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.] ERROR building one of the platforms: Error: /home/shakir/Documents/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/shakir/Documents/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)

I have set my ~/.profile file as follows

export ANDROID_HOME="/usr/local/android-sdk-linux"

export ANDROID_PLATFORM_TOOLS="/usr/local/android-sdk-linux/platform-tools"

export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_PLATFORM_TOOLS

and echo ANDROID_HOME give following results

/usr/local/android-sdk-linux

I am using Ubuntu 14.04. How to solve this issue and build cordova apps?

like image 396
McLosys Creative Avatar asked Sep 06 '15 07:09

McLosys Creative


2 Answers

you have probably used "sudo" for adding android platform.. a quick solution for this problem is:

  1. Restore the right folder permission to all the folder/subfolder of the platforms folder

  2. Delete the android platform with sudo cordova platform remove android

  3. Add the android platform with cordova platform add android DON'T USE THE SUDO! If there are errors without the sudo SO that's the problem! NEVER use the sudo thing or the project will have issue like this!

if you still have a problem then you may have installed cordova using sudo, also there is a solution for it:
first we have to set up npm for global installation so we can use it without sudo, the preferred way of enabling npm to install packages globally without breaking out of $HOME is to set a local node prefix. This is as easy as running:

echo prefix = ~/.node >> ~/.npmrc
echo 'export PATH=$HOME/.node/bin:$PATH' >> ~/.bashrc 
. ~/.bashrc    

then Running:

npm install -g cordova

it may results in:

Error: EACCES, permission denied '/home/yourusername/.config/configstore/update-notifier-cordova.json'

to fix it:

sudo chown yourusername:yourusername /home/yourusername/.config/configstore/update-notifier-cordova.json

After that, you can happily run npm install -g cordova without sudo, without running into permission conflicts and if something is completely broken and you want to start from scratch, all you need to do is remove your ~/.node directory.

Hope this help!

you can also look at these two links: source 1&2

like image 83
molhamaleh Avatar answered Nov 18 '22 08:11

molhamaleh


This error occurs, because of you didn't set your android sdk path correctly. First, find where the android-sdk folder located in your computer. Inside the android-sdk folder, there is a folder called 'platform-tools'. So you can identify android-sdk folder correctly. Then get the path to the android-sdk folder. Now open the terminal and enter following command,

export ANDROID_HOME="your android-sdk path"

Now run the project.

like image 42
Harshitha Palihawadana Avatar answered Nov 18 '22 07:11

Harshitha Palihawadana