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.
Unihedron
  • 10,902
  • 13
  • 62
  • 72
Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
  • 3
    Same happening for me... Installing it via brew solved it! – Sebastian Oct 23 '13 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 '15 at 12:44

7 Answers7

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.

Vimal Venugopalan
  • 4,091
  • 3
  • 16
  • 25
Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
  • 6
    Ant is in homebrew-core now. Simply use `brew install ant` – meaku Oct 29 '13 at 12:31
  • how can i install 'ant' for windows and set the path of it – Husnain Iqbal Oct 31 '13 at 12:53
  • @MuhammadHusnain: I suppose you should ask a separate question on Stack Overflow for this one – Mobiletainment Oct 31 '13 at 22:55
  • 3
    COMMAND UPDATE: ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)" – Felix Nov 21 '13 at 21:58
  • See http://superuser.com/questions/610157/how-do-i-install-ant-on-os-x-mavericks for updated `brew` instructions. – Roberto Jan 15 '14 at 20:58
  • 1
    Don't forget to execute "brew doctor" after installing brew and before using brew to install ant. – Wytze Feb 11 '14 at 12:45
  • i tried ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" it say unable to access 'https://github.com/Homebrew/homebrew/': Could not resolve proxy:"****" Failed during: git fetch origin master:refs/remotes/origin/master -n how to fix this – Charan Giri Feb 12 '14 at 05:18
  • i tried ruby -e "$(curl -fsSL raw.github.com/mxcl/homebrew/go/install) it returns ">" and do nothing please help me with the issue – Charan Giri Feb 12 '14 at 05:19
  • 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 – Mobiletainment Feb 12 '14 at 13:34
  • @Mobiletainment Yes that is the issue proxy made installation process go bad. – Charan Giri Feb 13 '14 at 04:15
  • 1
    @Mobiletainment I'm getting an error when I do brew install ant: curl: (22) The requested URL returned error: 404 Not Found Error: Download failed: http://www.gtlib.gatech.edu/pub/apache/ant/binaries/apache-ant-1.9.2-bin.tar.gz It looks like the file doesn't exist? Do I have to update brew maybe? – CR47 Feb 21 '14 at 18:09
  • Works like charm .. i just need to do .. brew update and then brew install ant -- ADT was already been installed on my Mac. – UberNeo May 07 '14 at 23:35
  • 10
    Don't forget `brew update` before you use it, if you already have homebrew installed.... – Christos Hrousis May 21 '14 at 00:47
  • 1
    This also fixed the problem on Yosemite – bodagetta Dec 28 '14 at 00:16
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

Coyote
  • 2,454
  • 26
  • 47
  • 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 06 '13 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 03 '15 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

John Mark
  • 2,458
  • 2
  • 21
  • 17
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

user2300434
  • 310
  • 2
  • 4
  • 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 03 '15 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
user1
  • 536
  • 5
  • 8
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.

Chivalryman
  • 101
  • 1
  • 2
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

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
K00kykelly
  • 31
  • 3