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?
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.
you have probably used "sudo" for adding android platform.. a quick solution for this problem is:
Restore the right folder permission to all the folder/subfolder of the platforms folder
Delete the android platform with sudo cordova platform remove android
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
Run following command in terminal :
export
PATH=${PATH}:/Users/Document/Android-sdk/tools:/Users/Documents/Android-sdk/platform-tools
You may also get this Error
Error: EACCES: permission denied, open '/home/yourusername/.cordova/lib/npm_cache/cordova-android/5.1.1/package/.npmignore'
to fix it use this command
sudo chown -R yourusername:yourusername /home/{username}/.cordova/lib/npm_cache/cordova-android/5.1.1/package
Related
I'minstalled PhoneGap and made one simple app that works on my tablet when using PhoneGap server and PhoneGap App for android. Now I want to makean APK but I'm gatting error when runsudo phonegap build android in APP folder:
miljan#Miljan-PC:~/Desktop/HelloWorld$ sudo phonegap build android
[sudo] password for miljan: [phonegap] executing 'cordova build
android'... cp: no such file or directory:
/home/miljan/Desktop/HelloWorld/icon.png
Running command:
/home/miljan/Desktop/HelloWorld/platforms/android/cordova/build
[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/miljan/Desktop/HelloWorld/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/miljan/Desktop/HelloWorld/platforms/android/cordova/build:
Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134: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)
In ~/.profile I have add this:
export ANDROID_HOME=/home/miljan/Android-SDK-Linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools
How I can slove this problem?
Anyone who can help?
I had the same problem when I was using ionic to build android. I used this solution to solve my problem
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
use the third solution and don't use the exact paths which are given here. In the android_home give the path of your sdk. in the android_tools give the path of tools in the sdk and in the third give the platform path given in the sdk.
and if you have problem after this too userchmod 777 /sdk/tools and chmod 777 /sdk/tools/android.
May this solution helps
Here is my android home & path
manish#manish-Vostro-2520:~/hello$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.7.0/bin:/home/manish/Android/Sdk/tools:/home/manish/Android/Sdk/platform-tools
manish#manish-Vostro-2520:~/hello$ $ANDROID_HOME
bash: /home/manish/Android/Sdk: Is a directory
but still when I execute sudo cordova build i am getting :
[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/manish/hello/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/manish/hello/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131: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)
Here is ~/.bashrc entry
#android path
export ANDROID_HOME=~/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Add the following code to .bashrc file by adding:
export ANDROID_HOME=/home/manish/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools
Note that existing shell won't have this path set, so it's recommended to restart your Linux machine once after adding those to the environment.
I believe this is because you are trying to build as a superuser. The best answer is to not use sudo while building, and simply use cordova build. Depending on how you setup node, this might not work for you.
Alternatively you could modify the bashrc located at /etc/bash.bashrc:
sudo -s
//login with superuser credentials
//then use an editor to modify, or just append to the file echo "export ANDROID... >> etc/bash.bashrc
vim /etc/bash.bashrc
Then simply add as other suggested:
export ANDROID_HOME=/path/to/android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools
For Linux, try the following command line:
export ANDROID_HOME=/< your installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
for Mac:
go to the Android Studio and configure/SDK Manager get the Android SDK Location.
then:
export ANDROID_HOME=Android SDK location
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools
When i'm executing "cordova platform add android" the command return this :
Error: /Users/brieuc/.cordova/lib/android/cordova/3.6.4/bin/create: Command failed with exit code EACCES
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:95:17)
at Process.ChildProcess._handle.onexit (child_process.js:818:12)
I've read that it could be a problem of permission so i've tried to use "sudo cordova platform add android" but the same error is returned.
I also tried to use chmod 777 on my project folder and platforms folder.
I tried to remove the platforms folder, the folder is recreated then same error is returned.
For your information, the commands "java", "ant", "cordova", "npm" are all recognize.
My only guess is that my Path to the SDK is wrong.
Here what i've done :
(I'm on Mac Yosemite for the information)
I downloaded the Standalone SDK tools.
I created a folder /Development/Android and added the unzipped downloaded folder (android-sdk-macosx).
For your information the "platforms" folder is empty.
i added to the /etc/paths the path to /Development/Android/android-sdk-macosx/tools
I'm not sure it should be here, any hints or solutions would be appreciated.
I don't think the problem is on your project. The problem seems to be in
/Users/brieuc/.cordova/lib/android/cordova/3.6.4/bin/create
which doesn't have the necessary rights to be executed. Try to apply something like this command for that folder
chmod -R 777 /Users/brieuc/.cordova/lib/android/cordova/3.6.4/bin
It should give it all rights and thus let create to be executed.
#Brieuc Here is solution for your new problem.
You need to specify Android SDK Path in .profile file located in your home.
In terminal,
sudo nano ~/.profile
Then add these lines at the end, save and close .profile. (You may have different paths for your Android SDK and ANT. ANT Path may not be necessary to set for you right now)
export ANT_HOME=/usr/share/ant
export ANDROID_HOME=/home/sagun/bin/android-sdk
export PATH=$PATH:$ANT_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Now at the terminal, you must notify the OS about the changes you made to .profile
source ~/.profile
If that doesn't do it, restart linux
Now, you may still face some permission issues, for that navigate to your android-sdk/tools and then enter
chmod +x android
Hope this helps you :)
i have installed android bundle and i have configured everything in .bashrc file and even when i say android in command line .. i am getting android manager .. but when i say ionic platform add android i am always getting error as "Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions." . i tried many way but issue not fixed .
my platform :
Ubuntu 14.04 64 bit
.bashrc file :
export HOME="/home/system"
export ANDROID_HOME="$HOME/adt-bundle-linux-x86_64-20140702/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/adt-bundle-linux-x86_64-20140702/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/system/adt-bundle-linux-x86_64-20140702/sdk/tools"
error while execution :
system#system-H81M-S1:/usr/share/nginx/www/myApp# ionic platform add android
npm http GET https://registry.npmjs.org/cordova-android/3.6.3
npm http 200 https://registry.npmjs.org/cordova-android/3.6.3
npm http GET https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
npm http 200 https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
Creating android project...
/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:126
throw e;
^
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
at /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/check_reqs.js:158:19
at _fulfilled (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:760:13)
at /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:821:14
at flush (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
Error: /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/
create: Command failed with exit code 8 at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/
cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
may i know how i can fix this error
I faced the same problem, and it's solved.
I think it's issue with the compatibility of the latest cordova with latest android.
As well as you've issue with the android home path.
In .bashrc file
export HOME="/home/indranil"
export ANDROID_HOME="$HOME/software/adt-bundle-linux-x86_64-20140702/sdk"
export PATH="$HOME/software/adt-bundle-linux-x86_64-20140702/sdk/tools:$ANDROID_HOME/platform_tools:$PATH"
Try to download the latest android SDK if you're using older version.
And download Android 4.4.2(API 19) from your android manager.
You can use the latest cordova (4.0.0) but if the issue is still there then use cordova (3.5.0-0.2.7), but if you want to upgrade or downgrade the cordova, remove the existing one using:-
npm uninstall -g cordova (If linux use sudo npm uninstall -g cordova)
If you are using linux don't use
sudo
commad at the time of installing cordoava, if you get any error, run the following commands
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
sudo chown -R `whoami` /usr/local
Then install cordova without sudo
npm install -g cordova#3.5.0-0.2.7
At the time of creating ionic app and adding android as platform don't use sudo command.
Cordova creates a .cordova directory in the home folder at the time of adding platform. Remove that directory before creating the new ionic application.
And after downloading the android(4.4.2), create an android virtual device using the command:
android avd
I have been struggling with this also (Ubuntu 14.04) and I remember accepting that just getting the cordova build command to work was too difficult for me :-). I was sure my PATHs were correct (tried root and user etc etc) and tried every solution I could find.
A comment by Stoicuta Alexandru On this page solved it for me. I quote:
If ANDROID_HOME is not set, cordova will search for it in home/android-sdk
So just putting my android sdk in the home-folder and (important) naming it android-sdk did it.
Hope to save some people some time...
I had the same problem but I found an alternative method i.e. using the Phonegap Developer App. You could install it to the emulator and use it.
In my case I first created the ionic app and ran other ionic commands using SUDO; that's why it was not working as sudo uses root profile.
This is how i fixed:
delete the /home/user1/.cordova (replace user1 with you user name)
i used "sudo rm" command to delete folder and all of its conents
i deleted the /home/user1/tmp folder so that when we run the cordova again it creates the new tmp folder with proper permission of current user
created new app using "ionic start app5" - this was the main issue as i previously was doing it with sudo
added platform using "ionic platform add android"
executed using "ionic run android"
remember that if from command line you can run "android" command and "java -version" command then above is perfect solution. let me know if you guys need any help from me.
After facing for many day with this issue i follow the instructions above and set my .bash_profile like this on MAC
#====================================================
export ANT_HOME=/usr/local/Cellar/ant/1.9.4/bin/ant
#
export HOME="/Users/User"
export ANDROID_HOME="$HOME/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk"
export PATH="$HOME/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/tools:$ANDROID_HOME/platform_tools:$PATH"
#
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${PATH}
#
export PATH=${PATH}:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/platform-tools:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/tools:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/build-tools/android-4.4W
#
NPM_PACKAGES="${HOME}/.npm-packages"
PATH="$NPM_PACKAGES/bin:$PATH"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
#
# Unset manpath so we can inherit from /etc/manpath via the manpath
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
UPDATE 1:
This was everything I did in the end:
sudo aptitude install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo aptitude update
sudo aptitude install nodejs
sudo aptitude install npm
sudo npm install -g cordova
sudo npm install -g phonegap
phonegap create my-app
cd my-app
export PATH=${PATH}:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/tools
sudo aptitude install ant
cordova platform add android
android create avd --name my_and --target 1
phonegap run android
Was any of that not neccessary?
ORIGINAL QUESTION:
On my Ubuntu 12.04 computer, I've just installed node.js with npm and cordova:
$ node -v
v0.10.23
$ npm -v
1.3.17
$ cordova -v
3.3.0-0.1.1
When I try to add android:
$ cordova platform add android
I get the following output:
Creating android project...
/usr/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
Error: An error occured during creation of android sub-project.
/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
at flush (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
at /usr/lib/node_modules/cordova/src/platform.js:244:30
at ChildProcess.exithandler (child_process.js:641:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:735:16)
at Socket.<anonymous> (child_process.js:948:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:466:12)
Anyone know why this is happening and how to resolve it?
I get the same issue with PhoneGap.
It's possible that the Android tools binaries are not in your path.
According to the PhoneGap docs (http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html), you need to include the Android SDK's tools and platform-tools in your PATH environment variable.
export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools
where Development is the path you installed your SDK.
Run the "android" command from your adt\sdk\tools folder and install the latest Tools and SDK. Also make sure your PATH has the right variables.
For this you will need ANT to be installed , a JAVA JDK and an Android SDK installed
JAVA_HOME (C:\Program Files\Java\jdk)
ANT_HOME ({ant location}\apache\apache-ant)
ANDROID_HOME ({android sdk location}\android-sdk)
Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
Close and re-open your cmd and run your command again.
I'm running Ubuntu 12.04 and was having the same problem as you until a few minutes ago.
The two things I've noted that I had missed during installation:
The Android version should be 19 and you should be able to type 'android' at the console and see some output or see a window pop-up. Make sure that you add the path to the folder where android.jar is located to your PATH variable, and set ANDROID_HOME to that same path as well. Typically, you would do this in your .bashrc file or in /etc/environment If you edit either of these files, you'll need to either 'source ~/.bashrc' or reopen your terminal to force it to reload the file. Type 'android' to make sure its working.
I observed that the cordova setup script was attempting to write files into a subdirectory 'add-ons' of the Android SDK. That directory does not exist in the Android 19 distribution itself. Consequently, I created it manually and made it writeable by my user account.
ex: Android distribution path:
/opt/android/
The path that its trying to write to:
/opt/android/sdk/add-ons
Once I had done that I was able to get past the problem you've noted above.
It looks like the cordova andorid library file corrupted in your home directory.
Try to remove home//.cordova directory and do this again cordova platform add android in your cordova project.
Make sure you have sourced /platform-tools and /tools to PATH.
Android
The Android command-line tools are built upon shell scripts. You must have the Android SDK's tools and platform-tools folders in your PATH!
Create a project
Run the create command with the following parameters:
Path to your new Cordova Android project
Package name, following reverse-domain style convention
Main Activity name
$ /path/to/cordova-android/bin/create /path/to/my_new_cordova_project com.example.cordova_project_name CordovaProjectName
It looks like this error could also be caused by the absence of a compatible Android SDK version (at the moment 4.2).
I use cordova.
2days I have same problem"java,ant,android,cordova,command test is ok,
but run cordova platform add android show me Error: An error occurred while listing Android targets".
Now I fixit use:
"chmod 777 ant and android sdk place"
,then it will work.
I use ubuntu 14.04 32bit,
if the problem still exist please make sure that you have the right permissions try
sudo chmo-R 777 /home/your-user-name/.cordova/
Also make sure that you are NOT using sudo to add Android as a platform
This is incorrect in the default Cordova installation
sudo cordova platform add android
Just do
cordova platform add android
I've searched a lot for this, and what worked for me was setting the shell variable $ANDROID_HOME to the path of the sdk/ folder in my adt-bundle directory from android. Use export to do this:
export ANDROID_HOME="/Users/YOUR_USER/Developer/adt-bundle/sdk/"
but be sure to change the directory to match yours.
Good Luck!
Not sure if someone else had a problem with this, but when removed and added my platform again, I realized in my config.xml I had <icon src='...'> and the path inside the src was wrong.
Here was the error output I received when I added the platform again:cp: no such file or directory: C:\Users\{pathtofile}.png.
After I fixed the path, it worked fine.
It can be that your cordova installation have been corrupted try to remove your .cordova folder "rm -R ~/.cordova"
And "run cordova platform add android" again