Using Gradle In Your Command Line Android Project

I’ve been developing mobile Android applications since 2011 and up until now I’ve been using nothing but Apache Ant for building them.

Now you’re probably like, it is 2015, why aren’t you using Gradle like the rest of the world? Well, I like Apache Ant, and I had no real reason to switch. However, I’ve decided this is the year I jump ship.

If you’re like me, a no IDE rebel coming from an Apache Ant world for Android development, this might help you out in making the switch to Gradle.

As a refresher, you’re probably familiar with creating your new Android applications from a terminal or command prompt like this:

Time to look at a few other differences in our process. Navigate into the freshly created project using your terminal or command prompt because we’re going to try to build the project.

Coming from an Ant world, you’re pretty familiar that ant debug will compile and create a debug version of our binary file in the bin directory of our project. Instead we are going to run ./gradlew assemble from a terminal or ./gradlew.bat assemble from a command prompt. This will create a debug version of our binary file in the build/outputs/apk directory of our project.

This is where we can make our project better for collaboration. Instead of downloading a bunch of external libraries to include in your project, you can add them as dependencies in your build.gradle file:

The above will include the Firebase SDK in your project when you run ./gradlew assemble.

Let’s say you’re now ready to build your project for release. In other words you are ready to sign your APK file to be uploaded to Google Play.

First make sure you have your signing keystore created. If you’re unfamiliar with this, visit my previous tutorial on the topic. Go ahead and add the keystore to the root of your project and add the following to your gradle.properties file:

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.