139

Today I tried PhoneGap/Cordova with Mac OS X Mavericks. Building for iOS went just fine, but building for Android wasn't without some guesswork.

I installed Android 4.2.2 via the Android SDK Manager (I had to use the older API v17 since it wasn't compatible with a newer one), added the PATH environment variables for the SDK's platform-tools and tools and thought I was ready to take off by running the command:

phonegap run android

Nevertheless, I got the following error:

[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project. ERROR : executing command 'ant', make sure you have ant installed and added to your path.
2
  • 3
    Same happening for me... Installing it via brew solved it!
    – Sebastian
    Oct 23, 2013 at 14:36
  • i went to the /bin Folder, and still I had the same command not found Problem, installing it with brew helped, I still dont understand why it wasnt working before, if I run ant -v from the bin Folder I dont Need to set Environment varibales, this is so strange...
    – LoveMeow
    Apr 28, 2015 at 12:44

7 Answers 7

361

The error message proved to be true as Apache Ant isn't in the path of Mac OS X Mavericks anymore.

Bulletproof solution:

  1. Download and install Homebrew by executing following command in terminal:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. Install Apache Ant via Homebrew by executing

    brew install ant

Run the PhoneGap build again and it should successfully compile and install your Android app.

14
  • 6
    Ant is in homebrew-core now. Simply use brew install ant
    – meaku
    Oct 29, 2013 at 12:31
  • 3
    COMMAND UPDATE: ruby -e "$(curl -fsSL raw.github.com/mxcl/homebrew/go/install)"
    – Felix
    Nov 21, 2013 at 21:58
  • 1
    Don't forget to execute "brew doctor" after installing brew and before using brew to install ant.
    – Wytze
    Feb 11, 2014 at 12:45
  • 1
    @CharanGiri: it seems that you're connecting to the internet via a proxy server. If so, please try to re-execute that command using a direct internet connection instead Feb 12, 2014 at 13:34
  • 10
    Don't forget brew update before you use it, if you already have homebrew installed.... May 21, 2014 at 0:47
45

You can install ANT through macports or homebrew.

But if you want to do without 3rd party package managers, the problem can simply be fixed by downloading the binary release from the apache ANT web site and adding the binary to your system PATH.


For example, on Mountain Lion, in ~/.bash_profile and ~/.bashrc my path was setup like this:

export ANT_HOME="/usr/share/ant"
export PATH=$PATH:$ANT_HOME/bin

So after uncompressing apache-ant-1.9.2-bin.tar.bz2 I moved the resulting directory to /usr/share/ and renamed it ant.

Simple as that, the issue is fixed.


Note Don't forget to sudo chown -R root:wheel /usr/share/ant

2
  • I did something very similar since I don't use homebrew or macports and on mine, I also did not have anything in my path for it. I downloaded the binary release, unzipped it and created a folder called ant in /usr/local then copied from the unzipped binary the bin and lib folder to /usr/local/ant, after that add /usr/local/ant/bin to your path and restart terminal and all was golden, just do what Coyote said and you will have phonegap CLI working in no time.
    – Robert-W
    Nov 6, 2013 at 22:18
  • 1
    This should be the accepted answer. Lean and clean. Install what you need. Using Apache Ant only takes 2 minutes of installing.
    – Michel
    Apr 3, 2015 at 14:55
28

As an alternative to homebrew, you could download and install macports. Once you have macports, you can use:

sudo port install apache-ant

5
  • 1
    @Goaler444: Are you using an old version of macports? Try port search ant and look for Apache Ant there.
    – John Mark
    Nov 27, 2013 at 19:14
  • Yep, that was it, updated ports by entering 'sudo port -v selfupdate' and it worked. Thanks :)
    – Goaler444
    Nov 27, 2013 at 19:30
  • @JohnMark i still get same error please help. i followed the process you mentioned do i need to install any other Feb 7, 2014 at 10:45
  • Is ant on your PATH? If you type which ant in the terminal do you get anything?
    – John Mark
    Feb 7, 2014 at 15:04
  • @JohnMark thank you for response when i typed which ant i got "/usr/local/bin/ant" Feb 11, 2014 at 5:04
21

it don't needed port and brew! because you have android sdk package.

.1 edit your .bash_profile

export ANT_HOME="[your android_sdk_path/eclipse/plugins/org.apache.ant_1.8.3.v201301120609]" 

// its only my org.apache.ant version, check your org.apache.ant version

export PATH=$PATH:$ANT_HOME/bin

.2 make ant command that can executed

chmod 770 [your ANT_HOME/bin/ant]

.3 test if you see below message. that's success!

command line execute: ant

Buildfile: build.xml does not exist!

Build failed

1
  • My Eclipse is installed in another location. After setting ANT_HOME="/Applications/eclipse/plugins/orig.apache.ant_1.8.3.v201301120609" it worked!
    – Michel
    Apr 3, 2015 at 15:14
14

I encountered the same issue when trying to use Cordova. Turns out I already had brew, try which brew, but it was outdated. So, I had to update it first:

  1. Update brew: brew update
  2. Install Apache Ant: brew install ant
0
7

In my case, I have macport installed already. I simply updated my macport:

sudo port selfupdate

sudo port upgrade outdated

Then install apache-ant:

sudo port install apache-ant

Finally, I add ant to my alias list in my .bash_profile:

alias ant='/opt/local/bin/ant'

Then you are all set.

0
3

For OSX your path needs to include /Users/yourusername

their example: /Development/adt-bundle/sdk/platform-tools
needs to be: /Users/yourusername/Development/adt-bundle/sdk/platform-tools

Not the answer you're looking for? Browse other questions tagged or ask your own question.