[Android SDK] Installing Gradle in command-line shell (MacOS X)

Once we install Android Studio (or just gradle itself), it is very comfortable to have it added to our PATH, which makes us able to run commands like

gradle task1

from any Android project’s folder.

One way to do that is adding gradle’s path to our PATH variable. Under MacOS X, this is done with the following steps.

1.- In terminal:

export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1

*We assume we’re using the bundled Gradle that comes with Android Studio. You can place gradle anywhere else, like your /Users/user folder, and use this location. Example:

export GRADLE_HOME=/Users/jimmy/gradle-2.2.1

2.- Now, let’s have a look at our PATH variable. In terminal:

echo $PATH

It should look like:

/usr/bin:/bin:/usr/sbin: ... (more system folders separated by ":" )

To append gradle’s folder at the end of our path:

export PATH=$PATH:$GRADLE_HOME/bin

Now, execute “echo $PATH” again, and you should see gradle’s folder appended in the end, separated by a “:”.

If you were successful on step 2, you should now be able to execute:

gradle –version

And see an output like:

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time:   ...
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.6.0_65 (Apple Inc. 20.65-b04-462)
OS:           Mac OS X 10.9 x86_64

Hope it helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s