I have built a Phonegap app and am now trying to integrate it with Phonegap Build. I'm following the very simple guide here.
So I am doing:
sudo npm install -g phonegap
sudo phonegap create hello com.example.hello HelloWorld
cd hello
sudo phonegap local build android
The last command results in the error:
The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: /bin/sh: 1: android: not found
I then did:
which android
with the result:
/home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android
which is the corrent path.
The phonegap version is 3.1.0-0.15.0.
Any ideas why I am getting this error?
Edit
If I run:
sudo phonegap local build /home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android
I get yet another error:
/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141
platformPath = path.join('.', 'platforms', platform.local);
^
TypeError: Cannot read property 'local' of undefined
at LocalBuildCommand.module.exports.addPlatform (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141:60)
at LocalBuildCommand.execute (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:95:32)
at LocalBuildCommand.run (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:70:10)
at Object.build (/usr/local/lib/node_modules/phonegap/lib/phonegap/util/command.js:28:25)
at CLI.module.exports (/usr/local/lib/node_modules/phonegap/lib/cli/local.build.js:34:20)
at CLI.module.exports [as argv] (/usr/local/lib/node_modules/phonegap/lib/cli/argv.js:66:17)
at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/bin/phonegap.js:24:21)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
Laters version of android sdk moved adb to platform-tools. Try to include both tools and platform-tools in your path. see
~/Tools/adt-bundle-linux-x86_64-20131030/sdk $ cat tools/adb_has_moved.txt
The adb tool has moved to platform-tools/
If you don't see this directory in your SDK, launch the SDK and AVD
Manager (execute the android tool) and install "Android SDK
Platform-tools"
Please also update your PATH environment variable to include the
platform-tools/ directory, so you can execute adb from any location.
I use following export commands.
export ANDROID_BUNDLE_HOME="$ATILLA_TOOLS/adt-bundle-linux-x86_64-20131030"
export ANDROID_SDK_HOME="$ANDROID_BUNDLE_HOME/sdk"
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export PATH=$PATH:$ANDROID_SDK_HOME/tools
export PATH=$PATH:$ANDROID_SDK_HOME/platform-tools
both adb and android should work in command line. Also try to use
phonegap local build android
without sudo.
see following example
$phonegap create deneme1
[phonegap] created project at /home/atilla/Projects/Denemeler/a/deneme1
$cd deneme1/
$phonegap local build android
[phonegap] adding the Android platform...
[phonegap] compiling
Android... [phonegap] successfully compiled Android app
After this successful message try to find your platform and apk file.
$ls -al platforms/
$ls -al platforms/android/
$ls -al platforms/android/bin
you should see HelloWorld-debug.apk in this directory.
-rw-r--r-- 1 atilla atilla 1542462 Ara 5 14:31 HelloWorld-debug.apk
install the phonegap npm global package with sudo, it's ok.
But then you should run phonegap with your own user
sudo npm install -g phonegap
phonegap create hello com.example.hello HelloWorld
phonegap local build android
executing with sudo you are switching to root user therefore environment variables as $PATH are not necessarily the same.
Try to Add your Android Path to your PATH Enviroment Variables.
if you use Linux, first try:
echo $PATH
This command display your PATH variable, search the Android path on this.
If you don't see the android path, you need to add that path on your enviroment variable.
Try this:
echo 'export PATH=$PATH:/home/user/mis_prog' >> /home/user/.bashrc
You must edit the configuration file of your login shell.
As usually the BASH shell is the most used, you must edit your /home/user/.bashrc.
For this you will use a text editor or just a command to make the task easier.
If you use some Windows Version, you can edith the enviroment variable PATH from system propertyes, something like this: http://www.computerhope.com/issues/ch000549.htm
Related
I am getting following error when I am running sudo ionic build android
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.
I have unzipped android-sdk inside '/opt'.android command runs fine from terminal.
I am setting my $ANDROID_HOME in ~/.bashrc
export ANDROID_HOME="/opt"
export PATH=$PATH:$ANDROID_HOME
export PATH=$PATH:/opt/platform-tools
export PATH=$PATH:/opt/tools
echo $ANDROID_HOME gives /opt.
echo $PATH gives /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/arvind/workspace:/opt:/opt/platform-tools:/opt/tools
P.S.: Running android from terminal gives following warning.( Don't know if it matters ).
(Android SDK Manager:6041): IBUS-WARNING **: The owner of /home/user1/.config/ibus/bus is not root!
If you have installed ionic globally(use sudo npm install -g ionic), you should not add sudo when you use ionic cli command. Just use:
ionic platform rm android
ionic platform add android
ionic build android
Hope this will help you, regards!
you just have to point out the bin directory inside android studio as:
inside ~/.bashrc
export ANDROID_HOME=/path/to/android-studio/
export PATH=$PATH:$ANDROID_HOME/bin
now echo $PATH and make sure the android studio is included in the 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!!
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.
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)"
I did some googleing but find nothing approriate.
Any help appreciated. Try it with an naked vm to be sure
having no nodejs install or dependency issue.
Christian
sudo apt-get install nodejs
sudo apt-get install nodejs-legacy
sudo npm install -g phonegap
sudo npm install -g cordova
sudo apt-get install ant
chris#mint16 ~/project/dev $ phonegap create my-app
[phonegap] create called with the options /home/chris/project/dev/my-app com.phonegap.helloworld HelloWorld
[phonegap] Customizing default config.xml file
[phonegap] created project at /home/chris/project/dev/my-app
chris#mint16 ~/project/dev $ cd my-app/
chris#mint16 ~/project/dev/my-app $ phonegap run android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
/home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at /home/chris/.cordova/lib/android/cordova/3.5.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:808:24)
at /home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:752:41)
at /home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:574:44
at flush (/home/chris/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
{ [Error: /home/chris/.cordova/lib/android/cordova/3.5.0/bin/create: Command failed with exit code 8] code: 8 }
[error] /home/chris/.cordova/lib/android/cordova/3.5.0/bin/create: Command failed with exit code 8
I've just faced the same issue, the problem was that path to sdk tools was not properly setup:
So try the following:
export PATH=$PATH:/usr/local/adt-bundle/sdk/tools
export PATH=$PATH:/usr/local/adt-bundle/sdk/platform-tools
export PATH=$PATH:/usr/local/adt-bundle/sdk/build-tools
I also hit the same issue, but just adding the various android sdk tools directories to the path as DKMudrechenko suggested above did not help. It turned out that I had not installed ant properly. I had downloaded it from apache.org and just added the ant 'bin' folder to my path, but apparently that wasn't good enough. However, after removing that entry from my path statement and adding ant via brew, I was then able to build the android cordova project successfully using the 'cordova build android' command.
i have been facing this issue on and off only to realise that the build fails for other errors in the code/configuration.
the process you have taken does skip one part where the android platform is added
corodova platforms add android
in the steps given above, you have created a project, traversed into the project directory and then ran the build, to which the phone gap checked the installed sdks by checking ANDROID_HOME and tried to set up the project for android.
you might want to run it in a correct order:
create project
move to the project directory
add platform
build / run.
i hope this helps
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